help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Anomalies with ${*}


From: Bill Gradwohl
Subject: Re: [Help-bash] Anomalies with ${*}
Date: Tue, 27 Mar 2012 07:08:05 -0600

Sorry about not supplying the output I see. I thought running it on your end would produce the same thing I see, but maybe that isn't true.

Here is the code again, and the output I get:

abc='  '
echo "abc->${abc}<-"
echo "->${abc// /}<-"

set -- '' '' ''
echo "*->${*}<-"
echo "->${*// /}<-"

set -- '' '' ''
IFS='' echo "IFS=''->${*}<-"

set -- '' '' ''
IFS= echo "IFS=->${*}<-"
============================
address@hidden ycc# ./tst
abc->  <-
-><-
*->  <-
->  <-
IFS=''->  <-
IFS=->  <-
============================
When abc contains 2 spaces, I can replace them and get a null string with the pattern substitution.
When I replace the abc with *, it no longer works as is evidenced by the tests.

I have a case where I have from 1 to 3 passed parameters. They could all be null strings. What I wanted to do is use * to aggregate all the passed parameters, knowing that they would be separated by the 1st char of IFS - a space. If all the parms are null strings, this would produce a null string for only 1 parm, a single space for 2 parms and 2 spaces for 3 parms. Using simple substitution of all spaces to null would tell me that all the parms were null.

Here is the simple statement I wanted to write :

{ [ $# -eq 0 ] || [ $# -gt 3 ] || [ "${*// /}" == '' ] ; } && syntax

Alternatively setting IFS='' when evaluating the ${*} should also produce a null string. It doesn't.

I don't see where this is clever or tricky code. Its a simple substitution. What else would * be good for if not to aggregate all the parms and then do something with the aggregation?


--
Bill Gradwohl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]