Hi.
I have been using Linux for a few years now and want to
learn how to program/write shell scripts.
So I decided to try and write a simple shell script that will process the arguments on a command line. It must:
(1) display the number of arguments.
(2) show if an argument is only numeric
(3) show if an argument is only alphabetic
(4) show if an argument is only alphanumeric
(5) exit with an error message if an argument is invalid
This is what I have done so far:
Code:
#!/bin/sh
echo -e "\nNumber of parameters: $#\n"
while test $# -gt 0; do
case "$1" in
[0-9]*) echo -e "Numeric: $1\n"
shift;;
[A-Za-z]*) echo -e "Alphabetic: $1\n"
shift;;
*) echo -e "Error: $1 is an invalid option.\n"
exit 1;;
esac
done
exit 0
I am having trouble with (4), how to detect an alphanumeric string.
would work to some extent, but it seems to pattern match the obvious.
I would appreciate any help.
Thanks,
J.