Getting Input from a File
$ wc < my.file
Keeping Your Data with Your Script
$ cat ext
# here is a "here" document
grep $1 <<EOF
It can be used as a shell script for simple phone number lookups:
$ ext bill
$ ext 555
grep $1 <<\EOF
sam $ 25
bill $ 9
$ cat myscript.sh
grep $1 <<-'EOF'
lots of data
can go here
it's indented with tabs
to match the script's indenting
but the leading tabs are
discarded when read
Getting User Input
Selecting from a List of Options
# cookbook filename: select_dir
directorylist="Finished $(ls /)"
PS3='Directory to process? ' # Set a useful select prompt
until [ "$directory" == "Finished" ]; do
printf "%b" "\a\n\nSelect a directory to process:\n" >&2
select directory in $directorylist; do
# User types a number which is stored in $REPLY, but select
# returns the value of the entry
if [ "$directory" = "Finished" ]; then
echo "Finished processing directories."
elif [ -n "$directory" ]; then
echo "You chose number $REPLY, processing $directory ..."
# Do something here
echo "Invalid selection!"
fi # end of handle user's selection
done # end of select a directory
done # end of while not finished
Prompting for a Password
read -s -p "password: " PASSWD
printf "%b" "\n"