================ Script Checklist -IAN! idallen@ncf.ca ================ This is a list of things to verify in your shell scripts: - script must start with a complete script header (interpreter, syntax, purpose, author, date, PATH, umask) - validate script command line arguments before using them - validate correct number of arguments, correct type (numbers, files, pathnames, etc.), correct permissions (if a pathname) - issue warnings or errors if arguments are missing, extra arguments are present, or if arguments aren't valid - validate any input received from the user via "read" - validate correct type (numbers, files, pathnames, etc.) - validate correct permissions (if a pathname) - issue warnings or errors if input isn't valid - issue error messages on stderr (not stdout) - error messages must contain the script name as well as useful help on (a) exactly what was found and (b) what was expected - never say just "illegal input" or "invalid input" or "too many" - always specify how many is "too many" or "too few" - Example: "$0: Expecting 3 file names; found $# ($*)" - issue prompts before reading input - prompt messages must appear on stderr so they don't get redirected - note: some menus might also be considered as prompts - quote every use of a shell variable, and don't miss any - quote every use, every time, to prevent wildcard expansion - I mean every use, every time - I mean it - you might get away with not quoting $$, $#, and $?, but that's all - I *really* do mean it - check the return codes of important commands in the script - minimal conditional checking syntax: command || exit $? - no need to check "echo" commands that write to screen - pick the important commands (don't clutter the whole script) - exit the script non-zero (bad status) when things go seriously wrong - don't keep processing bad data - exit if arguments are incorrect or not valid - exit if any important commands fail - use good programming style - indent your code correctly inside control structures (basically the same rules as in C language) - avoid lines longer than 80 characters (break and continue long lines using a backslash to escape the newline) - add useful, helpful comments (not useless ones) in front of code blocks (don't comment in front of every single line) - use good variable names, related to your algorithm (don't copy the poor names used by your instructor in examples) - don't repeat code (parametrize your algorithm) - test your scripts with problematic input - try wildcards, blanks, dashes, punctuation, empty strings, EOF, etc. - try no command line arguments and then hundreds of arguments - try short inputs, medium inputs, and huge long inputs - look for unquoted variables and put wildcards in them and watch your script blow up, then fix it by quoting all your variables - no input should cause a shell script to generate an internal error