
Important Linux features 225
DONE
INDEX
INDEX
When executing scripta a possible output is:
Wed Jan 3 03:51:07 PST 1996
/home/guest
scripta
fila
Note: the first line of the script should be:
#! /bin/sh
2. scriptb displays the contents of a pulse program:
• edit the file scriptb and enter:
dir=/opt/topspin/exp/stan/nmr/lists/pp
cd $dir
cat $1
$dir = the value of a parameter which is set in the script
$1 = an argument given to the script when it is executed
• make the file executable: chmod +x scriptb
• execute the script by typing its name and argument: ./scriptb zg30
3. Example of a control and loop structure in a shell script:
1
for i in ‘ls *.c‘ (for all files with the extension .c)
do
if grep strn $i
(if the file contains the string strn)
then
rm $i
(remove the file)
fi
done
1. "./" means: the command resides in the current directory. You can skip the "./" if the current
directory is part of the Linux search path. Type echo $PATH to see the Linux search path.
1. For more information on control and loop structures type man sh or man test.
Comentários a estes Manuais