[NTLUG:Discuss] Strings in BASH, an easier way?

Robert Citek robert.citek at gmail.com
Wed Dec 24 01:37:10 CST 2008


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



More information about the Discuss mailing list