POSIX Way to Check User Input in Shell Scripts

This post discusses how to validate both localized and non-localized user input in the POSIX shell.

Script to Check for Control Characters in File

Here is how to check for and display lines from a text file that contain control characters except for line endings (which are also control characters!). $ grep “[^[:print:]]” infile | cat -nvt Here is a simple script that will output a message if a text file contains any control characters other than line endings. #!/bin/bash if grep “[^[:print:]]” infile > /dev/null 2>&1 then printf “Control characters present in filen” else printf “No control characters in filen” fi This should work in all locales.