[NTLUG:Discuss] Strings in BASH, an easier way?
Leroy Tennison
leroy_tennison at prodigy.net
Wed Dec 24 01:44:25 CST 2008
Robert Citek wrote:
> On Wed, Dec 24, 2008 at 12:19 AM, Leroy Tennison
> <leroy_tennison at prodigy.net> wrote:
>> for i in `echo $PATH | cut -d: -f1-30 --output-delimiter=" "`; do
>> for j in `ls -1 $i`; do apropos $j; read; done;
>> done
>>
>> Not only is this a little more verbose than I want but the -f parameter
>> is a little "brittle" in that there doesn't appear to be any to say
>> "however many fields there are".
>
> Just leave off the last number:
>
> echo $PATH | cut -d: -f1- --output-delimiter=" "
>
> IHMO, once you're getting into moderately sophisticated data
> structures (e.g. arrays), you're better off with a scripting language
> like awk.
>
> Regards,
> - Robert
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
Nice tip, dutifully noted for future reference.
More information about the Discuss
mailing list