Practical definition / general rule of thumb
-
scripts:
-
perform similar tasks many times
-
flow control (i.e., conditional execution) supported
-
parameters (arguments, switches) may be passed
-
variable manipulation supported
Example:
%> cat script1
#!/bin/csh
# script1 — R.A.Jansen, Oct 23 2002 — rename a bunch of image files
if ( $#argv < 5 ) then
echo "Syntax: script1 <inproot> <outroot> <imexten> <old1 new1> [old2 new2]"
echo " [[old3 new3] [old4 new4] ...]"
exit
endif
set inp = "$1"
set out = "$2"
set ext = "$3"
shift ; shift ; shift
while ( a == a )
if ( "" != "$1" && "" != "$2" ) then
echo "\\cp −p $inp$1$ext $out$2$ext"
\cp −p $inp$1$ext $out$2$ext
shift ; shift
else
break
endif
end
%> chmod +x script1
%> script1 im NGC3710_ .fits 001 B 002 V 003 R
\cp −p im001.fits NGC3710_B.fits
\cp −p im002.fits NGC3710_V.fits
\cp −p im003.fits NGC3710_R.fits
|