Previous Table of Contents Next


OPTIONS

The Bourne shell has a number of options that specify your environment and control execution. They can be enabled/disabled with the set command or on the sh or jsh command line. Some options are only available on invocation.

Enabling/Disabling Options

sh [/+options] enable/disable the specified options
jsh [/+options] enable/disable the specified options; enable job control (see JOB CONTROL section)
set [/+options] enable/disable the specified options (see also set)

List of Options

–a automatically export variables that are defined
–c commands read and execute commands (w/sh only)
–e exit if a command fails
–f disable file name expansion
–h remember locations of functions on definition instead of on execution (see also hash)
–i execute in interactive mode (w/sh only)
–k put variable assignment arguments in environment
–n read commands without executing them
–p do not set effective ids to real ids
–r run a restricted shell (w/sh only)
–s read commands from standard input (w/sh only)
–t exit after reading and executing one command
–u return error on substitution of unset variables
–v display input lines as they are read
–x display commands and arguments as executed

CONDITIONAL EXPRESSIONS

The test and [...] commands are used to evaluate conditional expressions with file attributes, strings, and integers. The basic format is:

       test expression
       or
       [ expression ]

where expression is the condition you are evaluating. There must be whitespace after the opening bracket, and before the closing bracket. Whitespace must also separate the expression arguments and operators. If the expression evaluates to true, then a zero exit status is returned, otherwise the expression evaluates to false and a non-zero exit status is returned.

test File Operators

–b file true if file exists and is a block special file
–c file true if file exists and is a character special file
–d file true if file exists and is a directory
–f file true if file exists is a regular file
–g file true if file exists and its setgid bit is set
–k file true if file exists and its sticky bit is set
–L file true if file exists and is a symbolic link
–p file true if file exists and is a fifo special file or a pipe
–r file true if file exists and is readable
–s file true if file exists and its size is greater than zero
–S file true if file exists and is a socket
–t n true if file descriptor n is open and associated with a terminal device
–u file true if file exists and its set user-id bit is set
–w file true if file exists and is writable
–x file true if file exists and is executable

Test String Operators

–n string true if length of string is not zero
–z string true if length of string is zero
string true if string is not set to null
string1 = string2 true if string1 is equal to string2
string1 != string2 true if string1 is not equal to string2
string = pattern true if string matches pattern
string != pattern true if string does not match pattern

Test Integer Operators

exp1 –eq exp2 true if exp1 is equal to exp2
exp1 –ne exp2 true if exp1 is not equal to exp2
exp1 –le exp2 true if exp1 is less than or equal to exp2
exp1 –lt exp2 true if exp1 is less than exp2
exp1 –ge exp2 true if exp1 is greater than or equal to exp2
exp1 –gt exp2 true if exp1 is greater than exp2

Other test Operators

!exp true if the given expression is false
\(exp\) true if exp is true; used to group expressions (\ used to escape parentheses)
exp1 –a exp2 true if both exp1 and exp2 evaluate to true
exp1 –o exp2 true if either exp1 or exp2 evaluate to true


Previous Table of Contents Next
1