Re: Bash Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



William L. Maltby wrote:
> On Mon, 2009-08-17 at 19:55 +0100, James Bensley wrote:
>> I can't think of the exact syntax at the minute but something like;
>>
>> if $# => 4 then
>>     for i = 1 to ($# - 4)
>>         echo "arg number $i is $expr($i)"
>>     next
>> fi
> 
> $ echo $*
> 1 2 3 4
> $ \
>> while [ "$1" != '' ] ; do
>> echo $1
>> shift
>> done
> 1
> 2
> 3
> 4
> $
> 
>> <snip>

Note that (a) the args are gone as you shift them out, so a real script 
would need to save $1 into a named variable before each shift if it 
wants the value later, and (b), '' is a legitimate and possible argument 
  on a shell command line so it might be better to check $# for the 
count remaining.

-- 
   Les Mikesell
    lesmikesell@xxxxxxxxx
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux