Home | Mirror | Search |
例 33.8. Using select to make simple menus
#!/bin/bash OPTIONS="Hello Quit" select opt in $OPTIONS; do if [ "$opt" = "Quit" ]; then echo done exit elif [ "$opt" = "Hello" ]; then echo Hello World else clear echo bad option fi done
例 33.9. Using the command line
#!/bin/bash if [ -z "$1" ]; then echo usage: $0 directory exit fi SRCD=$1 TGTD="/var/backups/" OF=home-$(date +%Y%m%d).tgz tar -cZf $TGTD$OF $SRCD
例 33.10. Reading user input with read
In many ocations you may want to prompt the user for some input, and there are several ways to achive this. This is one of those ways:
#!/bin/bash echo Please, enter your name read NAME echo "Hi $NAME!"
As a variant, you can get multiple values with read, this example may clarify this.
#!/bin/bash echo Please, enter your firstname and lastname read FN LN echo "Hi! $LN, $FN !"