Previous Table of Contents Next

cj> pwd; ls -x # perform a pwd then list the directory, two commands on
# one line
cj> ls | wc # count number of entries in directory
cj> sort /etc/passwd > wfile & # sort the system passwd file and store the output in the
# "wfile"
cj> cut -f1 -d: /etc/passwd |& # place in background and connect two-way pipe to
# command.
cj> read -p USERNAME # read first line from pipe
cj> print $USERNAME # print first line (USERNAME)


The command syntax used by the shell is described in Module 23. Module 23 also discusses the syntax of UNIX commands.


A word beginning with a # informs the shell that the remainder of the line is a comment. The following forms are valid shell comments.

     # This is a shell comment
     cat phone.db # display the phone database


Aliasing allows you to assign a command to a name. If an alias has been defined, then the text of the alias (replacement string) is substituted in place of the alias at execution time. If the first word of a command matches the alias, then the substitution occurs. For further explanation of the alias command refer to Module 4.


The shell checks each word for a beginning ~. If a word begins with a ~, the shell reads the word up to the next / or blank. It then attempts to match this word with a user name in the /etc/passwd file. If a match is found, then the ~user_name is replaced with the user's HOME directory path. This is referred to as a tilde substitution. If ~/ is interpreted by the shell, the $HOME variable is substituted in its place.

Tilde substitution is also performed if a :~ is interpreted or if a ~ is the first character of a keyword value. The general formats of a tilde command follow.

Tilde Substitution Description

~/dir Reference your $HOME directory.
~user_name/dir Reference user_name's $HOME directory.
~- Reference the previous working directory. The value of OLDPWD is substituted.
~+ The absolute path of the present working directory. The value of PWD is substituted.

C Shell
The C shell does not support the ~- or ~+ commands.

The following examples show what they would be converted to by the shell.

cj> cd ~yourlogin # equivalent to "cd /u1/ts/yourlogin"
cj> cd ~/bin # equivalent to "cd $HOME/bin" or "cd/u1/ts/mylogin/bin"
cj> cd ~- # equivalent to "cd /u1/ts/yourlogin"


Command substitution is done when the shell reads a command from between two grave accents (`command`). The shell executes the command and substitutes the output of the command in place of the `command`. All new-lines are removed from the standard output of the executed command. Command substitution can also be done by using $(command). This syntax makes it easier to nest command substitution commands.

Backslashes (\) used to escape other characters are removed before the command is executed. Backslashes are used to escape grave accents and backslashes. By escaping grave accents you can nest command substitutions.

In the case of a command substitution being enclosed in double quotes ("...`...`..."), a backslash will be left intact unless it is escaping a double quote. For further information on using the backslash to escape characters in command substitution refer to the Quoting section of this module.

The following example illustrates how command substitution can be used for different purposes.

     cj> echo You have `ls | wc  -l` files in `pwd`.
     cj> DATE=`date "+%D"`
     cj> for FILE in `ls`
        echo $FILE.ext

The `cat file` command should be replaced by the faster `< file` command. The cat command is invoked as a separate process while the "<" redirection symbol is an internal ksh read.


Variables are described in Module 99.


Variable substitution or expansion and referencing are described in Module 99.


Arrays are described in Module 99.


The shell scans the command line and separates the words into distinct arguments. The words are separated based on internal field separators. The shell's IFS variable defines which characters separate words. The default value of the IFS variable is space, tab, and new-line.

Explicit null arguments, " " or ' ', are retained. Implicit null arguments, arguments that have no value, are removed. The following examples illustrate the implicit and explicit blank interpretation syntax.

      cj> NUM=

In the last line the $NUM parameter is removed and the " " becomes positional parameter 1. The " " and ' ' are valid arguments and are passed into the program myscript as positional parameters 1 and 2. The last set of words enclosed in double quotes is passed to myscript as one argument.


Filename generation is described in Module 54.

Previous Table of Contents Next