How to raise and take care of shell scripts: check input

Every input is evil?

Yes, of course. At least if it's coming from a source you don't have under control completely. Input may come using the command line, from a file, from a command's output, ... The input data can be empty, can contain unexpected values (a letter when you expect digits), can produce numeric overflows, can have a format which is interpreted in a wrong way (some programs expect that a number with a leading zero is an octal value, in this case a 09 is invalid), input can contain control characters, ...

Your main principle should be: Don't use input data coming from untrusted sources without validation. The list below is a selection of tools, which you can use to validate input. It's not nearly complete - there are almost unlimited possibilities to do the job. Where you can get more information? Bingo: in the manual pages!

To analyse input values, you should use your imagination! Want to check, if the input is a valid user or group name? getent. Want to know, if an existing process id is given? ps. Is the file system you want to unmount, already mounted? mount or df. Is the input really a date? date - I could extend this list almost infinitely, but then you would never see the end of this page %-/