Edmund J. Sutcliffe
Thoughtful Solutions, Creatively Implemented and Communicated
Edmund's KornShell Quick Reference -
1
2
3
4
Click here
for a printable version of this page.
Command Language
I/O redirection and pipe
% command running in foreground (interactive)
% command >file redirects stdout to file
% command 2>err_file redirects stderr to err_file
% command >file 2>&1 redirects both stdout and stderr on file
% (command > f1) 2>f2 send stdout on f1, stderr on f2
% command >>file appends stdout to file
% command <file redirects stdin from file
% command << text Read standard input uo to line identical
to text
% command1 | command2 redirects stdout from command1 into stdin
of command2 via a pipe
Ex : du ~ | sort -nr | head
% command | tee f1 f2 ... The output of command is sent on
stdout and copied into f1, f2, ...
% command& running in background
% nohup command& running in background even after log out
% set -o monitor to have a message when a background job ends
stderr : to print on it in a script, use the option -u2 in command
print
Shell variables
# Warning : no blank before of after the = sign
# Integers :
n=100 ; x=&n
integer t
typeset -r roues=4 # definition of a CONSTANT (read only)
typeset -i2 x # declares x as binary integer
typeset -i8 y # declares y as octal integer
typeset -i16 z # guess what ?
# Strings :
lettre="Q" ; mot="elephant"
phrase="Hello, word"
print "n=$n ; lettre=$lettre ; mot=$mot ; phrase=$phrase"
typeset -r nom="JMB" # string constant
# Arrays : one dimensional arrays of integers or strings
# automatically dimensionned to 1024
animal[0]="dog" ; animal[1]="horse" ; animal[3]="donkey"
set -A flower tulip gardenia " " rose
print ${animal[*]}
print ${flower[@]}
print "cell#1 content : ${flower[1]}
Pattern matching
| Wild card |
matches |
| ? |
any single char |
| [char1char2... charN] |
any single char from the
specified list |
| [!char1char2... charN] |
any single char other than
one from the specified list |
| [char1-charN] |
any char between char1 and
charN inclusive |
| [!char1-charN] |
any char other than between
char1 and charN inclusive |
| * |
any char or any group of
char (including none) |
| ?(pat1|pat2...|patN) |
zero or one of the specified
patterns |
| @(pat1|pat2...|patN) |
exactly one of the specified
patterns |
| *(pat1|pat2...|patN) |
zero, one or more of the
specified patterns |
| +(pat1|pat2...|patN) |
one or more of the specified
patterns |
| !(pat1|pat2...|patN) |
any pattern except one of
the specif. patterns |
Tilde Expansion :
~ your home directory (ls ~)
~edmund home directory of another user
~+ absolute pathname of the working directory
~- previous directory (cd ~-) ( or cd -)
Control characters
< ctrl_c> Cancel the currently running process (foreground)
< ctrl_z> Suspend the currently running process
then : > bg : to send it in background
or > fg : continue in foreground
or > kill -option : sends signals (such as TERMINATE)
ex > kill -9 pid : to kill a background job
kill -l : to find out all the signals
supported by your system.
< ctrl_d> End of file character
$ stty to see what are the KILL & <EOF> characters
|