Re: [SLUG] Bash Help Needed

From: Michael Fisher (desnotes@gmail.com)
Date: Sat May 17 2008 - 17:24:53 EDT


On Sat, May 17, 2008 at 5:15 PM, Eben King <eben01@verizon.net> wrote:

> 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?
>
>
Your way is cleaner so I ended up using it. Yes having two arguments reports
blank, but that ends up being more of a check for the user to let them no
one one is allowed

-----------------------------------------------------------------------
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:50 EDT