Magic numbers. Executables have headers, which start with special values called magic numbers. These numbers are part of a convention between compilers/assemblers and the operating system kernel: the magic numbers tell the OS kernel how to load the rest of the file when the executable file is invoked with the exec system call. The first line of a shell script (or more generally, an interpreted script file) must be the characters #!/full/path/to/interpreter -- with shell scripts, the path is typically one of /bin/sh, /bin/csh, or /software/common/gnu/bin/bash -- where the character sequence #! serve as a magic number, indicating to the kernel that the file should be interpreted as a script file and that immediately following the #! is the name of the interpreter which should read the file and interpret the contents as commands. (Note that for all the standard shells, # is how comments are started, so the first line is read by the shells as a comment.)
$#, $?, $*, $@.
Control flow constructs. while, until, if constructs, which controls execution by examining the exit status of commands. The case statement, which performs pattern matching, filename style.
test, and grep. at. Alarm clock example script because I just moved and can't find my alarm clock in the packing boxes:
$ cat > beep.me #!/bin/sh while test ! -f $HOME/.stop do echo '\a\a\aWake up!\a\a\a\r\c' >> /dev/console done ^D $ chmod +x beep.me $ at 0830 beep.me ^D $(This relies on the fact that I stay logged in on the console over night.)
bsy@cse.ucsd.edu, last updated