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

49 lines
1011 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
echo
if test -z "$1"
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
2002-06-17 13:17:07 +00:00
echo
2006-06-22 14:28:13 +00:00
if /usr/bin/test -z "$1" # Equivalent to "test" builtin.
# ^^^^^^^^^^^^^ # Specifying full pathname.
2002-06-17 13:17:07 +00:00
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if [ -z "$1" ] # Functionally identical to above code blocks.
# if [ -z "$1" should work, but...
#+ Bash responds to a missing close-bracket with an error message.
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
2001-07-10 14:25:50 +00:00
2005-08-28 18:12:12 +00:00
if /usr/bin/[ -z "$1" ] # Again, functionally identical to above.
# if /usr/bin/[ -z "$1" # Works, but gives an error message.
# # Note:
# This has been fixed in Bash, version 3.x.
2001-07-10 14:25:50 +00:00
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
exit 0