School of Computing. Dublin City University. Home Blog Teaching Research Contact
Online coding site:
coders JavaScript worlds |
|
|
Shell programming - Text file of multiple Unix/Linux commands (e.g. "if" condition then execute command, else other command).
The combination of one-liner command-line plus multi-line Shell programs gives you a programmable User Interface, where you can quickly write short programs to automate repetitive tasks.
Shell program
= an interpreted program (i.e. not compiled).
Also known as a "Shell script" or "batch file" of UNIX commands.
Like .BAT files on Windows command line.
$ chmod +x file
$ file $ file &
Advantage: Does not have to be executable. Does not have to be in PATH.$ sh prog
Advantage: Can easily see what the file is from a directory listing.$ prog.sh
I don't use either of these.
$1 1st command-line argument $2 2nd command-line argument ... $* all arguments # comment exit exit the Shell script exit 0 exit with a return code that other progs can query $? return code of last prog executed
# test if 1st argument = "0" if test "$1" = "0" then echo "yes" else echo "no - first argument is $1" fi