#!/bin/bash
# validAlphaNum -- 确保输入内容仅限于字母和数字
validAlphaNum()
{
validchars="$(echo $1 | sed -e 's/[^[:alnum:]]//g')"
if [ "$validchars" = "$1" ] ; then
return 0
else
return 1
fi
}
echo -n "Enter input: "
read input
if ! validAlphaNum "$input" ; then
echo "Your input must consist of only letters and numbers." >&2
exit 1
else
echo "Input is valid."
fi
exit 0