20090528

./isempty.sh[3]: test: Specify a parameter with this command.

Ok I know test wants parameter. But how? Roasted? Half cooked?

isempty()
{
NAME=$1
if [ -n $NAME ]; then echo not empty!
else echo it is empty!
fi
}
echo "name: \c"
read name
isempty $name

I feel there is a proper way than to append 2>/dev/null

1 comment:

  1. you should use quotes:
    -n "$NAME"

    though I find this more readable
    if [ "$NAME" != "" ]; then ...

    in decades of shell use, I may have used '-n' once; I had to look it up.
    easier to remember quotes (always!) and use a simple string compare.

    ReplyDelete