verifing input from bash read
Hello,
I have a simple shell script that read input from a user. The input is only a number or single letter. What would be the best way to verify the input or remove any harmful characters ? I was thinking about using: --snip-- read inputvariable echo ${inputvariable} | grep -E '^[[:alnum:]]{1,2}$' > /dev/null if [ $? -eq 0 ]; then continue because the input is only 1-2 digits and is either a number or letter else exit 1 fi --snip-- Is that enough though ?? Michael. |
you could use case.
you can use single characters or wildcards. the *) at the end is like the default So if there are no matches it falls through to the end. e.g: Code:
also look at the select statement maybe try Code:
select file in *;do cksum $file;done |
All times are GMT -5. The time now is 06:43 AM. |