School of Computing. Dublin City University.
Online coding site: Ancient Brain
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
is an interpreted program (not compiled, source code read at runtime).
Also known as a "Shell script" or "batch file".
(Windows command line has a similar concept of
.BAT files.)
$ 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
$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