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

51 lines
873 B
Bash
Raw Permalink Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
# Call this script with at least 10 parameters, for example
# ./scriptname 1 2 3 4 5 6 7 8 9 10
2002-07-22 15:11:51 +00:00
MINPARAMS=10
2001-07-10 14:25:50 +00:00
echo
echo "The name of this script is \"$0\"."
# Adds ./ for current directory
echo "The name of this script is \"`basename $0`\"."
2001-09-04 13:27:31 +00:00
# Strips out path name info (see 'basename')
2001-07-10 14:25:50 +00:00
echo
2001-09-04 13:27:31 +00:00
if [ -n "$1" ] # Tested variable is quoted.
2001-07-10 14:25:50 +00:00
then
2001-09-04 13:27:31 +00:00
echo "Parameter #1 is $1" # Need quotes to escape #
2001-07-10 14:25:50 +00:00
fi
if [ -n "$2" ]
then
echo "Parameter #2 is $2"
fi
if [ -n "$3" ]
then
echo "Parameter #3 is $3"
fi
# ...
2002-07-22 15:11:51 +00:00
2001-07-10 14:25:50 +00:00
if [ -n "${10}" ] # Parameters > $9 must be enclosed in {brackets}.
then
echo "Parameter #10 is ${10}"
fi
2003-01-06 21:25:36 +00:00
echo "-----------------------------------"
echo "All the command-line parameters are: "$*""
2002-07-22 15:11:51 +00:00
if [ $# -lt "$MINPARAMS" ]
then
2003-01-06 21:25:36 +00:00
echo
2004-04-28 12:08:07 +00:00
echo "This script needs at least $MINPARAMS command-line arguments!"
2002-07-22 15:11:51 +00:00
fi
2001-07-10 14:25:50 +00:00
echo
exit 0