The sequence
The sequence
set
function
.
These are faster than calling shell scripts, but less portable.
Test is a command used for testing one or more conditions in an if command. Format
exit
without a code leaves
the code undefined. If you use an exit code in one place, you
must give one for all exit statements.
if [ $# -ne 3 ] then echo "Usage: $0 arg1 arg2 arg3 exit 1 fior
test $# - ne 3 && echo Usage: $0 a1 a2 a3 && exit 1
if [ ! -r $1 ] then echo $1 is unreadable exit 2 fi
echo "..." | ... cat file | ...The first sends an explicit string down a pipeline, the second sends the contents of a file down a pipeline.
sed
is often used to delete text from lines, or to keep
some text in lines.
To delete text, you match the text and replace it with nothing.
sed 's/text//'
To keep text, you match it and save it as \1, \2, etc. The rest of the text is matched as well. The replacement text is only the saved stuff.
sed 's/stuff\(text\)stuff/\1/'
for
or while
loops.
Write a shell script that lists all the executable files in the current directory
for file in `ls` # or for file in * do if [ -x $file ] then echo $file fi doneor
ls | while read file do if [ -x $file ] then echo $file fi done
This page is copyright Jan Newmarch.
It is maintained by Jan Newmarch.
email:
jan@newmarch.name
Web:
http://jan.newmarch.name/
Last modified: 13 Mar, 2001