quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Features (csh)

Each shell has its own set of features. Those of the C Shell are discussed below.

   

space.gif

  ../images/main/bullet_star_pink.gif Command history

The history mechanism maintains a list of recently used command lines, called events. Provides a shorthand for reexecuting previous commands. To use history:

   

space.gif

1. Set the history variable:

set history = 100

   

space.gif

2. Issue the history command and view the output:

   

space.gif

 %history
 35  12:34   sort < unsorted > sorted.list
 36  12:34   cat sorted.list
 37  12:35   ls * > unsorted
 38  12:35   cat unsorted
 39  12:35   ls
 40  13:06   history
 41  13:08   alias
 42  13:11   ls
 43  13:11   vi .cshrc
   

space.gif

3. To save history events across all login sessions, set the savehistory variable:

set savehistory = 50

   

space.gif

  ../images/main/bullet_star_pink.gif Event reexecution

Allows you to specify a shorthand for reexecuting a previous event. Works with the history list.

   

space.gif

!! - repeats last command

!number - repeats numbered command from history list

!string - repeats last command starting with string

   

space.gif

  ../images/main/bullet_star_pink.gif Modifying previous events

Allows you to correct typos in previous command, or modify it to create a new command.

^old^new - changes the string "old" to the string "new" in the last command issued

!number:s/old/new/ - changes numbered command from history list; substitutes the string "old" with the string "new". Note that there is no space between number and :

   

space.gif

  ../images/main/bullet_star_pink.gif Aliases

The alias command allows you to define new commands. Useful for creating shorthands for longer commands. The syntax is.

   

space.gif

alias entered_command executed_command

   

space.gif

Some examples:

   

space.gif

alias m more

alias rm "rm -i"

alias h "history -r | more"

alias www "cd /home/deepak/asic-world"

   

space.gif

To view all current aliases:

   

space.gif

alias

   

space.gif

To remove a previously defined alias:

   

space.gif

unalias alias_name

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Filename Generation

When you give the shell abbreviated filenames which contain special characters (metacharacters), it can generate filenames which match existing files. Some examples appear below:

   

space.gif

Command

Description

ls *.txt

list files with .txt suffix

ls [abc]*

list files with names that start with a, b or c

lpr prog?.c

print files named prog?.c where ? is any character

cd ~jsmith

change to user jsmith's home directory

You can "turn off" filename generation by setting the noglob variable. This will permit special characters to be interpreted literally. For example:

   

space.gif

set noglob

   

space.gif

  ../images/main/bullet_star_pink.gif Filename Completion

The shell will complete a filename for you if you type in only enough characters to make the name unique. This feature is a great time saver and helps to prevent typos when trying to type long filenames.

   

space.gif

To use filename completion, you need to set filec, either on the command line or in one of your initialization files.

   

space.gif

set filec

   

space.gif

Then, when specifying a filename, type the part which is unique and hit the escape key (C shell) or tab key (TC Shell). For example, if you had a directory with a long name, such as "Introduction.UNIX.Filesystems", you could cd to that directory by using the cd command with only a portion of the file's name, provided that the portion you specify is unique (no other files have similar names)

   

space.gif

cd Intro<ESC>

   

space.gif

Note: typing a portion of a filename and then hitting CTRL-D instead of ESCape or TAB will display a list of the filenames which match.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Variables (csh)

Each shell has its own set of variables and rules for using variables. Those associated with the C Shell are discussed below.

  • The shell has variables which are predefined as well as variables which you define (user defined).
  • Shell variables control many aspects of how your shell environment behaves. Modifying these variables (and creating new ones) allows you to customize your shell environment.
  • Shell variables are used extensively when creating shell scripts (covered later).
   

space.gif

Variables can be

  • local - current shell only
  • global - current shell and child processes/shells
  • string - treated as character
  • numeric - treated as numbers
  • arrays - contain more than one value

Commands used to declare and manipulate shell variables:

   

space.gif

Command

Description

set

assigns non-numeric string variables locally

unset

removes a previously "set" variable

set

shows all "set" variables

setenv

assigns non-numeric string variables globally

unsetenv

removes a previously setenv variable

setenv

shows all setenv variables

@

assigns numeric variables locally

echo $variable

displays value of variable

   

space.gif

Examples

   

space.gif

Command

Description

set name=Deepak

Sets variable name to value of Deepak

unset name

Unsets the variable name

set path=($path . ~/bin)

Adds to current setting of string array variable path

echo $HOME

Displays value of variable HOME

set colors=(red green blue)

Assigns three values to the string array variable colors

@ count = 1

Sets numeric variable count to one

@ count = ($count + 1)

Adds one to numeric variable count

set counts = (1 22 4 9)

Assigns 4 values to numeric array variable counts

@ counts[2] = 5

Assigns values to second element of numeric array variable counts

@ echo $counts[3]

Displays value of third element of numeric array variable counts

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Predefined Shell Variables.

A number of shell variables are predefined by the shell itself or inherited from the system environment. Some of the more common ones are described below.

   

space.gif

Variable

Description

$

Contains the process id of the current shell

argv

Contains the command line arguments for an invoked command. argv is an array, with $argv[0] set to the name of the invoked command, $argv[1] set to the first argument, $argv[2] set to the second argument...and so on. $argv[*] can be used to specify all arguments. You may also use the shorthand $n where n is the number of the argument.

#argv

Set to the actual number of arguments in argv, excluding argv[0]

cdpath

Expands the search path for the cd command. By default, the cd command issued with a simple filename will search only the working directory. Use cdpath to increase the number of directories searched.

CWD or cwd

Holds that name of the working/current directory.

echo

Causes the shell to echo the command before executing it. Use set/unset to turn this on/off.

filec

Enables file completion. Use set/unset to turn this on/off.

history

Controls the size of the history list. 100 is recommended as safe size. If the number is too large, the shell may run out of memory.

HOME or home

The pathname of your home directory

ignoreeof

Prevents exiting the shell by typing CTRL-D, and thus, prevents accidentally logging off. Use set/unset to turn this on/off.

noclobber

Prevents you from accidentally overwriting a file when you redirect output. Use set/unset to turn this on/off.

noglob

Prevents the shell from generating/expanding ambiguous filenames. Use set/unset to turn this on/off.

notify

Tells the shell to notify you immediately when a background job completes. Ordinarily, notification will wait until the next shell prompt to prevent interruption of work. Use set/unset to turn this on/off.

PATH or path

Specifies the path that the shell searches when asked to execute a command. If an executable is not found in the path, you must specify its full pathname.

prompt

Allows you to customize the shell prompt. By default, the C shell prompt is simply a percent sign (%). For example, to display the machine name you are logged into as part of your prompt set prompt = "`hostname -s`% "

savehist

Specifies how many the number of command events to save as history after you logout. These events are saved in a file called .history in your home directory. The shell uses these as your initial history after you login again.

shell

Contains the pathname of the shell

status

Contains the exit status of the last executed command

USER or user

Contains you login userid

verbose

Causes the shell to display each command after a history substitution. Use set/unset to turn this on/off.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Initialization Files

System-wide shell initialization files are common on UNIX systems. These files can be "sourced" automatically by the shell and are typically setup by the System Administrator for the local environment.

   

space.gif

Some examples of system-wide initialization files might be:

   

space.gif

/etc/environment

/etc/profile

/etc/cshrc

/etc/login

   

space.gif

Every shell provides a means for the user to customize certain aspects of the shell's behavior. These customizations usually permit you to augment and/or override the system-wide defaults. User customizations are specified in initialization files located in the top level of your home directory. Naming: Depending upon the shell, you must name your initialization file(s) accordingly.

   

space.gif

Executed during interactive login

   

space.gif

.login

csh, tcsh

.profile

sh, ksh, bash

.bash_profile

bash (alternative 1)

.bash_login

bash (alternative 2)

   

space.gif

Executed for every new shell

.cshrc

csh, tcsh

.tcshrc

tcsh

.kshrc

ksh

.bashrc

bash

   

space.gif

The C shell uses two files to set user preferences:

   

space.gif

* .cshrc

  • runs at each login before the .login file
  • runs whenever another shell is created
  • runs when a new window is opened
  • runs when many utilities are invoked
  • typically sets alias information, path variable, filec, prompt, etc.
   

space.gif

* .login

  • runs at invocation of login shell, after the .cshrc file
  • typically sets terminal characteristics and one time shell options and environment variables
   

space.gif

After changing your .login or .cshrc files, you must "source" them for the changes to take effect:

   

space.gif

source .login

source .cshrc

   

space.gif

The system administrator may/may not provide you with default .cshrc and .login files when you first obtain your userid. If they are provided, be careful about modifying them - especially removing specifications which are required for your local system.

   

space.gif

Example .cshrc and .login files are provided below:

   

space.gif

* .cshrc file

* .login file

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Logout Files

You are able to specify commands which the shell will execute upon logout. These commands are kept in a file located in the top level of your home directory.

   

space.gif

.logout - csh, tcsh

.bash_logout - bash

   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com