[plug] string manipulation
Craig Dyke
grail at westnet.com.au
Sat Apr 22 18:58:01 WST 2006
Bruce M. Axtens wrote:
> I could suggest a Tcl version, but every time I mention Tcl at PLUG
> meetings, some people start making regurgitation noises.
>
So where is the suggestion?
I am happy to experiment.
Craig
> Bruce.
>
>
> On Saturday, April 22, 2006, at 03:26 PM, Bernd Felsche wrote:
>
>> Craig Dyke <grail at westnet.com.au> writes:
>>
>>> I am looking for two answers here:
>>
>>> 1. Is there a better way than what I will show below?
>>
>> There is always a better way. It's in the decimation of the baked
>> confection.
>>
>>> 2. How is what I am doing wrong as I have to split operation into two
>>> (will show what I mean)?
>>
>>> Currently:
>>
>>> I have written a script which uses find to set a variable --> var=`find
>>> / -name $what_i_am_looking_for`
>>
>> This find may set sveral results into the same variable: A list.
>>
>>> The what_i_am_looking_for variable is et earlier and is the name of a
>>> directory on my system.
>>
>>> My task is to set a new variable equal to the name of the parent
>>> directory to what I have found.
>>
>>> This is what works at the mo: temp=${what_i_am_looking_for%/*}
>>> newVar=${temp##*/}
>>
>>> What I was trying to do was combine both:
>>> newVar=${${what_i_am_looking_for%/*}##*/}
>>
>> Try a nested dirname. That'll also work if the file is in the root
>> directory.
>>
>> for ff in $var ; do
>> parent=`dirname \`dirname $ff\``
>> # do stuff in the $parent
>> done
>>
>> Your bashrc probably contains a (debugged) function definiton for
>> "dirname" so it won't fork as often as it would for these things.
>> If you feel like it, define your own say "parentname" function,
>> building on "dirname" so that you won't have to use the "ugly"
>> escape above.
>> --
>> /"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
>> \ / ASCII ribbon campaign | "Laws do not persuade just because
>> X against HTML mail | they threaten."
>> / \ and postings | Lucius Annaeus Seneca, c. 4BC - 65AD.
>>
>> _______________________________________________
>> PLUG discussion list: plug at plug.org.au
>> http://www.plug.org.au/mailman/listinfo/plug
>> Committee e-mail: committee at plug.linux.org.au
>>
>
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>
More information about the plug
mailing list