LDP/LDP/guide/docbook/abs-guide/ex29.sh

30 lines
954 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2004-10-03 17:40:48 +00:00
# Testing ranges of characters.
2001-07-10 14:25:50 +00:00
2001-09-04 13:27:31 +00:00
echo; echo "Hit a key, then hit return."
2001-07-10 14:25:50 +00:00
read Keypress
case "$Keypress" in
2004-10-03 17:40:48 +00:00
[[:lower:]] ) echo "Lowercase letter";;
[[:upper:]] ) echo "Uppercase letter";;
[0-9] ) echo "Digit";;
* ) echo "Punctuation, whitespace, or other";;
esac # Allows ranges of characters in [square brackets],
#+ or POSIX ranges in [[double square brackets.
# In the first version of this example,
#+ the tests for lowercase and uppercase characters were
#+ [a-z] and [A-Z].
# This no longer works in certain locales and/or Linux distros.
2005-03-21 13:51:11 +00:00
# POSIX is more portable.
2004-10-03 17:40:48 +00:00
# Thanks to Frank Wang for pointing this out.
2001-09-04 13:27:31 +00:00
2004-07-12 13:08:16 +00:00
# Exercise:
# --------
# As the script stands, it accepts a single keystroke, then terminates.
2005-03-21 13:51:11 +00:00
# Change the script so it accepts repeated input,
2004-07-12 13:08:16 +00:00
#+ reports on each keystroke, and terminates only when "X" is hit.
# Hint: enclose everything in a "while" loop.
2001-07-10 14:25:50 +00:00
exit 0