|
Command | Meaning | Command | Meaning |
: | Do nothing (just do expansions of arguments). | let | Arithmetic variable assignment. |
. | Read file and execute its contents in current shell. | newgrp | Start new shell with new group ID. |
alias | Set up shorthand for command or command-line | print | Expand and print arguments on standard output. |
bg | Put job in background. | pwd | Print working directory. |
break | Exit from surrounding for, select, while, or until loop. | read | Read a line from standard input. |
case | Multi-way conditional construct. | readonly | Make variables read-only (unassignable). |
cd | Change working directory. | return | Return from surrounding function or script. |
continue | Skip to next iteration of for, select, while, or until loop. | select | Menu generation construct. |
echo | Expand and print arguments. | set | Set options. |
exec | Replace shell with given program. | shift | Shift command-line arguments. |
exit | Exit from shell. | time | Run command and print execution times. |
export | Create environment variables. | trap | Set up signal-catching routine. |
eval | Process arguments as a command line. | typeset | Set special characteristics of variables. |
fc | Fix command (edit history file). | ulimit | Set/show process resource limits. |
fg | Put background job in foreground. | umask | Set/show file permission mask. |
for | Looping construct. | unalias | Remove alias definitions. |
function | Define function. | unset | Remove definitions of variables or functions. |
getopts | Process command-line options. | until | Looping construct. |
if | Conditional construct. | wait | Wait for background job(s) to finish. |
jobs | List background jobs. | whence | Identify source of command. |
kill | Send signal to process. | while | Looping construct. |
|
|
Variable | Meaning | Default | Set by: |
# | Number of arguments given to current process. |   |   |
- | Options given to shell on invocation. | See above. |   |
? | Exit status of previous command. | none | ksh |
$ | Process ID of shell process. | none | ksh |
_ | Last argument to previous command. | none | ksh |
! | Process ID of last background command. | none | ksh |
CDPATH | List of directories for cd command to search. | none | User |
COLUMNS | Width of display in columns (for editing modes and select). | 80 | System Administrator |
EDITOR | Used to set editing mode; also used by mail and other programs. | /bin/ed | User, System Administrator |
ERRNO | Error number of last system call that failed. | none | ksh |
ENV | Name of file to run as environment file when shell is invoked. | none | User, System Administrator |
FCEDIT | Default editor for fc command. | /bin/ed | User, System Administrator |
FPATH | Search path for autoloaded functions. | none | User |
HISTFILE | Name of command history file. | $HOME/.sh_history | User, System Administrator |
HISTSIZE | Number of lines kept in history file. | 128 | User, System Administrator |
HOME | Home (login) directory. | none | System Administrator |
IFS | Internal field separator; list of characters that act as word separators. | SPACE, TAB, and NEWLINE. | User |
LINENO | Number of line in script or function that just ran. | none | ksh |
LINES | Height of display in line (for select command). | 24 | System Administrator |
LOGNAME | User name. | none | System Administrator |
MAIL | Name of file to check for new mail. | none | System Administrator |
MAILCHECK | How often (in seconds) to check for new mail. | 600 seconds | User, System Administrator |
MAILPATH | List of file names to check for new mail, if MAIL is not set. | none | System Administrator |
OLDPWD | Previous working directory. | none | ksh |
OPTARG | Option to argument being processed by getopts. | none | ksh |
OPTIND | Number of first argument after options. | none | ksh |
PATH | Search path for commands. | /bin:/usr/bin | User, System Administrator |
PPID | Process ID of parent process. | none | ksh |
PS1 | Primary command prompt string. | $ | User |
PS2 | Prompt string for line continuations. | > | User |
PS3 | Prompt string for select command. | #? | User |
PS4 | Prompt string for xtrace option. | + | User |
PWD | Current working directory. | none | User |
RANDOM | Random number between 0 and 32767 (215 - 1) | none | ksh |
REPLY | User's response to select command; result of read command if no variable names given. | none | System Administrator |
SECONDS | Number of seconds since shell was invoked. | none | ksh |
SHELL | Full pathname of shell. | none | System Administrator |
TERM | Type of terminal user is utilizing. | none | System Administrator |
TMOUT | If set to positive integer, number of seconds between commands after which shell automatically terminates. | 0 (unlimited) | ksh |
VISUAL | Used to set editing mode. | /bin/ed | User, System Administrator |
|
|
these are options that can be turned on with the set -o command. All are initially off except where noted. Abbrevs, where listed, are arguments to set that can be used instead of the full set -o command (e.g., set -a is an abbreviation for set -o allexport). the abbreviations are actually backward-compatible Bourne shell options. |
Option | Abbreviation | Meaning |
allexport | -a | Export all subsequently defined variables. |
errexit | -e | Exit the shell when a command exits with a non-0 status. |
bgnice |   | Run all background jobs at decreased priority (on by default). |
emacs |   | Use emacs-style command-line editing. |
gmacs |   | Use emacs-style command-line editing, but with a slightly different meaning for CTRL-T. |
ignoreeof |   | Disallow CTRL-D to exit the shell. |
markdirs |   | Add / to all directory names generated from wildcard expansion. |
monitor | -m | Enable job control (on by default). |
noclobber |   | Don't allow > redirection to existing files. |
noexec | -n | Read commands and check for syntax errors, but don't execute them. |
noglob | -f | Disable wildcard expansion. |
nolog |   | Disable command history. |
nounset | -u | Treat undefined variables as errors, not as null. |
privileged | -p | Script is running in suid mode. |
trackall | -h | Substitute full pathnames for commands in alias expansions. |
verbose | -v | Print commands (verbatim) before running them. |
vi |   | Use vi-style command-line editing. |
viraw |   | Use vi mode and have each keystroke take effect immediately. |
xtrace | -x | Print commands (after expansions) before running them. |
|
~ | Home Directory | { | Start Code Block |
# | Comment | } | End Code Block |
$ | Variable Expressions | ; | Shell Command Separator |
& | Background Job | ' | Strong Quote |
* | String Wildcard | " | Weak Quote |
( | Start Subshell | < | Input Redirect |
) | End Subshell | > | Output Redirect |
\ | Quote Next Character | / | Pathname Directory Separator |
| | Pipe | ? | Single-character Wildcard |
[ | Start Character-set Wildcard | ] | End Character-set Wildcard |
|
${varname:-word} |
Return a default value if varname is undefined |
${varname:=word} |
Set a variable to a default value if varname is undefined |
${varname:?message} |
If varname is undefined, print message and terminate script. |
${varname:+word} |
If varname exists, return word, otherwise return nothing. |
|
Operators | Examples |
Operator | Meaning | Expression | Matches |
  | x | x |
*(exp) | 0 or more occurrences of exp | *(x) | Null string, x, xx, xxx,... |
+(exp) | 1 or more occurrences of exp | +(x) | x, xx, xxx, ... |
?(exp) | 0 or 1 occurrences of exp | ?(x) | Null string, x |
@(exp1|exp2|...) | exp1 or exp2 or ... | @(x) | x |
!(exp) | Anything that does not match exp | !(x) | Any string except x |
|
Syntax | Meaning |
statement1 && statement2 | Execute statement1, and if its exit status is 0, execute statement2 |
statement1 || statement2 | Execute statement1, and if its exit status is not 0, execute statement1. |
|
Operator | True If... | Operator | True If... |
str=pat* | str matches pat | str1>str2 | str1 is greater than str2 |
str!=pat | str does not match pat | -n str | str is not null (has length greater than 0) |
str1<str2 | str1 is less than str2 | -z str | str is null (has length 0) |
|
These are the operators used with the [[...]] construct. They can be logically combined with && ("and") and || ("or") and grouped with parentheses.
|
Operator | True If... | Operator | True If... |
-a file | file exists | -x file | You have execute permission on file, or directory search permission if it is a directory. |
-d file | file is a directory | -G file | Your group ID is the same as that of file. |
-f file | file is a regular file (i.e. not a directory or other special type of file) | -L file | file is a symbolic link. |
-r file | You have read permission on file | -O file | You own file. |
-s file | file exists and is not empty | file1 -nt file2 | file1 is newer than file2 |
-w file | You have write permission on file | file1 -ot file2 | file1 is older than file2. |
|
Arithmetic Operators | Relational Operators |
Operator | Meaning | Operator | Meaning |
+ | Plus |   |
- | Minus | < | Less than |
* | Times | > | Greater than |
/ | Division (with truncation) | <= | Less than or equal to |
% | Remainder | >= | Greater than or equal to |
<< | Bit-shift left | == | Equal |
>> | Bit-shift right | != | Not equal |
& | Bitwise and | && | Logical and |
| | Bitwise or | || | Logical or |
~ | Bitwise not |   |
^ | Bitwise exclusive or |   |
|
These are the arguments to the typeset command. |
  | With no option, create local variable within function. |
-L | Left justify and remove leading blanks. |
-R | Right justify and remove trailing blanks. |
-f | With no arguments, prints all function definitions. |
-f fname | Prints the definition of function fname. |
+f | Prints all function names. |
-ft | Turns on trace mode for named function(s). |
+ft | Turns off trace mode for named function(s). |
-fu | Defines given name(s) as autoloaded function(s). |
-i | Declare variable as integer. |
-l | Convert all letters to lowercase. |
-r | Make variable read-only. |
-u | Convert all letters to uppercase. |
-x | Export variable, i.e., put in environment so it is passed to subshells. |
Back to