In: Computer Science
Write a script that accepts a single character argument (command line parameter), then checks to see if the argument is an upper- or lower-case letter. (You do not have to do any error checking. Just assume that the user will enter a single character.) Hint: use grep to search for a member of the character class [a-z]. Then use the exit code (in an if statement) to see if grep was successful and write the proper response. If the argument is a letter, print (display to screen) “You entered a letter.” If the argument is not a letter, print “You did not enter a letter.”
letter.sh:
#reads a command lone argument and checks for a
upper-case or lower-case letter
if grep -q "[a-zA-Z]" <<< "$1"
#if block
then
#prints output if it is a
letter
echo "You entered a letter"
#exit code for if statement
exit 1
#else block
else
#printf otput if the character is
not a letter
echo "You did not enter a
letter"
fi #end of if block
Output:
