Re: [SLUG] Bash Help Needed

From: Eben King (eben01@verizon.net)
Date: Sat May 17 2008 - 17:15:45 EDT


On Sat, 17 May 2008, Michael Fisher wrote:

> Thanks for all the help....here what I happened on and got it to work:
>
> if [ "$#" != "1" ]; then
>
> cnt=10
> printf "is blank\n"
>
> else
> cnt=$1
> printf "is not blank\n"
>
> fi
>
> Basically it is checking arguments and if there is not one only, it is
> considered blank.

For a numeric test such as that, there's no need for quotes ($# is not
user-supplied, so there's no easy way to make it have a space) you should do

if [ $# -ne 1 ] ; then
   cnt=10
   printf "is blank\n"
else
   cnt="$1" # always quote untrusted data:
            # foo "15 ; if [ `id` -eq 0 ] ; then rm -r / ; fi"
   printf "is not blank\n"
fi

You know that if $# == 2, it reports "is blank", right?

-- 
-eben    QebWenE01R@vTerYizUonI.nOetP    royalty.mine.nu:81
PISCES:  Try to avoid any Virgos or Leos with the Ebola
virus. You are the Lord of the Dance, no matter what those
idiots at work say.  -- Weird Al, _Your Horoscope for Today_
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:51:39 EDT