By default the shell will search for external commands based on the value of the PATH environment variable. If the command can not be found in any of the directories specified by the path, it searches the current directory. If you specify a path with the command, the shell will not search the path for the specified command. Instead, it only searches the path specified on the command line.
The for command lets you execute a specified list of commands. The syntax for this command is:
for identifier [in word ...]; do list; done
where identifier is a variable which is assigned the value(s) specified by word ... and executes the commands specified by list. If the word option is not specified, the shell executes the list of commands for each positional parameter that is set.
The select command will write the specified words to standard error. The syntax is:
select identifier [in word...];do list ;done
where identifier is assigned the value of the word matched by input.
The case command can be used to executes commands based on a particular setting of another variable. The syntax for this command is:
case word in pattern [[ ( ] pattern [ | pattern] ... ) list;;] ...esac
where word is the variable to match with one of the specified patterns. When a matching pattern is found, the commands specified by list are executed. The vertical bar is used to denote an "or" operation.
You can also use an if construct to specify conditions in the script. The syntax for this command is:
if List ;then list [elif List; then list] ... [;else list] fi
where the commands specified by list are executed if the last command executed by List has a return value of zero. The elif construct represents an else if phrase and the corresponding list commands are executed if the previous List returns a non zero value and the last command executed by the List following the elif phrase returns a value of zero. The else clause is executed only if all other conditions are return non-zero values.
The while clause can be used to execute a list of commands while a certain condition holds true. The syntax for the while command is:
while List ;do list ;done
where the commands specified by list are executed after the last command specified by the List variable returns a zero value. The shell will continue to execute the commands until the last command specified in List returns a non-zero value.
The until command works like the while command except the return values are reversed. This means the commands in list are executed as long as the last command specified by List returns a non-zero value. This repeats until the last command in List returns a zero value.
Commands executed within parentheses are run within a subshell. To execute commands within the current shell, enclose them in braces ('{' and '}').
Specifying an expression within a double set of brackets will cause the shell to evaluate the expression. If the expression has a true value, it will have a return code of zero.
You can define a function for use with other shell commands. To do this, specify the name of the function followed by a set of parenthesis. The commands that are associated with the name should follow, and be enclosed within braces and separated by semi-colons. The syntax for this is:
name () {list;}
where name is the name of the function and list is a set of commands that are executed when the function is invoked.
The Korn shell will also let you measure the execution time of a command. To do this, specify the command as the argument to the time command.
Expr Brief Description Expr Brief Description ------------------------------------------------------------------------------ -a file T if file exists -b file T if file exists & a block file -c file T if file exists & a char file -d file T if file exists & a directory -f file T if file exists & a normal file -g file T if file exists & setgid bit set -k file T if file exists & sticky bit set -n str T if length of str is > 0 -o opt T if opt is on -p file T if file exists & a FIFO file -r file T if file exists & readable -s file T if file exists & > 0 bytes in size -t desc T if desc is open -u file If file exists & setuid bit set -w file T if file exists & no write access -x file T if file exists & executable -z str T if the length of str = 0 -L file T if file exists & a link -O file T if file exists & owned by user -G file T if file exists & same group id -S file T if file exists & a socketThe next table shows operands that can be used between two files, strings , expressions or patterns. The symbols fi, str, expr, and pat are used to represent these respective items. The description states when the condition will evaluate with a TRUE return code.
Item Brief Description Item Brief Description ------------------------------------------------------------------------------- fi1 -nt fi2 fi1 newer than fi2 fi1 -ot fi2 fi1 older than fi2 fi1 -ef fi2 fi1 refers to same file as fi2 str = pat str matches the pat str != pat str does not the pat str1 < str2 str1 comes before str2 str1 > str2 str1 comes after str2 exp1 -eq exp2 exp1 equals exp2 exp1 -ne exp2 exp1 not equal to exp2 exp1 -lt exp2 exp1 less than exp2 exp1 -gt exp2 exp1 greater than exp2 exp1 -le exp2 exp1 < = exp2 exp1 -ge expr2 exp1 >= exp2 (exp) T if exp is to true !exp True if exp is false exp1 & & exp2 T if exp1 & exp2 are true exp1 || exp2 True if exp1 or exp2 are true
Command Description ------------------------------------------------------------------------------- : [argument] The null command returns a zero exit value . file [argument...] Executes commands specified in file using the search path and not starting a subshell alias [name[=value]] Specify a nickname for the command, value bg [job...] Place the specified job into the background break [n] Exits the nth iteration from the for, while, or until loop. cd [directory] Changes to the specified directory, or to $HOME if none specified continue [n] Resumes the nth iteration of the for, while, or until loop echo [string] Writes string to standard output eval [list] Executes the commands specified in list exec [list] Executes the commands in list in place of the current shell exit [n] Causes the shell to exit with a return code of n export [name] Marks the specified name for export to the environment of subsequent commands. fc [first [last]] Selects a range of commands from first to last from the command history fg [job...] Places the job in the foreground jobs [job] Displays all the active jobs or the specified job kill job Terminates the execution of the specified job newgrp [group] Same as the /usr/bin/newgrp command let expression Evaluates the specified expression print [arguments] This is the shell output mechanism pwd Displays the current working directory read [name ...] Reads one line from standard input and assigns to name readonly [name...] Marks name to be read-only return [n] Causes a function to return a value of n set [flag [argument]] Sets the specified flags shift [n] Shifts the command line arguments to the left n places ($0 is never shifted) times Displays the accumulated user and system times for processes running from the shell trap [command] [n] Runs command when the shell receives a signal n typeset [name...] Sets attributes and values for shell parameters ulimit [flag [var]] Sets or queries process size limits using a specified flag umask [nnn] Sets the access mode mask to be used with newly created files. unalias name Removes the alias for the nickname name unset [name...] Removes the specified variable, name from the environment wait [n] Waits for the child process whose process number is n or all if none specified whence name For each name specified, indicate how it would be used as a command
A command can be told to execute in the background if an ampersand (& ) is placed at the end of the command line. When the shell sees the ampersand, it will display the job number for that process in square brackets followed by its process ID. If the background process tries to read from the terminal, it will be stopped. These jobs will also stop when trying to write output if the stty tostop command has been given to the shell.
When using any of the commands to control a job (bg, fg, and kill), an argument must be passed specifying which job is to be affected. This argument represents a specific job and can be specified by the job ID preceded by a percent sign. As an alternative, you can specify the command string after the percent sign to specify a job. If you wish to specify a series of jobs that match a specific string, precede the string with the %? characters. If no arguments are given, the commands will assume you wish to choose the previously affected job.
Before logging out, you should know the statuses of any jobs which still exist. If you have stopped jobs, the shell will not allow you to logout. Before you can logout, you must resume or kill the job. If you have a job running in the background, you will be allowed to logout and the process will continue running. This, however, is strongly discouraged because it ties up valuable system resources.
There is an exception to the filename substitution rules. Any file that begins with a period will not match a pattern. In other words, to see a list of all files that begin with a period, you would have to use the pattern .* . If the pattern does not match any file names, the pattern is returned. Infinite recursion can occur if files have names that include any of the special pattern characters.
Redirection symbols should be used after the command and any of its arguments. The redirection symbol should then be followed by the file or command for which the redirection is occurring. The < symbol is used to redirect standard input from the specified file. The > sign redirects standard output to the specified file. The > > symbol appends the output of the command to file specified, creating it if it does not exist. You can redirect a specific file descriptor by placing its number directly after the redirection symbol and an ampersand. For example, cc prog1 > > & 2 error.file will redirect all errors produced by the c compiler to the file error.file. You can redirect more than one file descriptor by placing each one with its own redirection symbol.
alias nickname=command [options]
where nickname is the nickname to be used and command is the AIX command with the specified options being aliased. When the shell finds a command being executed that matches a nickname in the alias list, it will replace the nickname on the command line with command options. This substitution is followed by a space character so the substituted string does not combine with the remainder of the command line.
The Korn shell lets you create and assign values to system environment variables as well as user defined variables. A variable name is a sequence of letters and numbers and can include underscores. The only restriction is that it not begin with a number. A value can be assigned to a variable by typing the variable name followed by an equals sign and then the value to be assigned. Do not place any spaces around the equals sign, or they will be included as part of the variable name or value. If you wish to use spaces in the value, place the entire value within quotation marks (" "). If double quotation marks are used, the shell will still perform variable name substitution. In other words, values are substituted for their variables. Once a value has been assigned to a variable, it can be used by placing a $ before the variable name. If the value is to be used within a string, you can include the variable name (but not the $) within braces. The braces will separate the variable name from the rest of the string. For example, to show the value of the environment variable HOME, use the command
echo $HOME
Environment variables can be exported to subsequent subshells by using the export command.
Below is a table showing the system environment variables and a brief description about them.
Variable Brief Description ------------------------------------------------------------------------------- CDPATH The search path for the cd command COLUMNS Defines the width of the edit window for the shell edit modes EDITOR Specifies which editor option is on ENV If set, parameter substitution is performed on the value to generate the path ERRNO A value set by the most recently failed subroutine FCEDIT The default editor name for the fc command FPATH The search path for function definitions HISTFILE The path name of the file to store the history of commands issued HISTSIZE The number of commands stored in the history file HOME The subdirectory that becomes current upon login and as a default for cd IFS Characters that are to be used as internal field separators LANG Determines the locale to use when LC_ALL does not specify one LC_ALL Determines the locale to be used to override any previously set values LC_COLLATE Defines the collating sequence to use when sorting LC_CTYPE Determines the locale for the interpretation of sequence of bytes LC_MESSAGES Determines the language in which messages should be written LINENO The line number in the current line within the script or function being executed LINES Determines the column length for printing select lists MAIL The path name of the file used by the mail system to detect the arrival of new mail MAILCHECK The number of seconds that the shell lets elapse before checking for new mail MAILPATH A list of programs separated by colons where the shell will notify you of new mail MAILMSG The mail notification message OLDPWD The previous working directory set by the cd command OPTARG The value of the last argument processed by the getopts special command OPTIND The index of the last option argument processed by the getopts special command PATH The search path for commands separated by colons PPID The process number of the parent of the shell PS1 The string to be used as the primary system prompt PS2 The value of the secondary prompt (when the shell finds a new-line character) PS3 The value of the selection prompt string used within a select loop PS4 This value precedes each line of an execution trace PWD The present working directory RANDOM Generates a random number between 0 and 32767 REPLY Set by the select and read special commands when no arguments are given SECONDS The number of seconds since the shell was invoked SHELL The path name of the shell (should be exported by the $HOME/.profile script) TMEOUT The number of minutes the shell remains inactive before it exits.
Key Brief Description Key Brief Description ------------------------------------------------------------------------------- [CTRL][F] Moves forward one character [CTRL][B] Moves back one character [CTRL][A] Moves to the start of the line [CTRL][E] Moves to the end of the line [CTRL][D] Deletes the current character [ESC][D] Deletes the current word [ESC][H] Deletes the previous word [ESC][C] Capitalizes the current word [CTRL][K] Deletes from to end of line [CTRL][Y] Restores the last item removed [CTRL][J] Executes the current line [CTRL][P] Fetches the previous command [CTRL][N] Fetches the next command line [ESC]# Insert a comment in the history [CTRL][O] Executes line and fetches next [ESC][L] Changes the current word to lowercase [ESC]< Fetches the oldest history line [ESC]> Fetches the newest history line
The value of the last command to be executed will store its return code in the $? variable.
You can see the value of user variables by using the set command. The env command can be used to display the values of the system variables.
Many books exist in the library and your local bookstore that cover AIX (UNIX) and the Korn shell. Search through these for one that explains the amount of information you need at a level corresponding to your expertise with AIX.
(c) Copyright UCF Computer Services I& R Support 08/17/93