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

Chris Cox cjcox at acm.org
Fri Dec 26 09:31:21 CST 2008


Leroy Tennison wrote:
> I'm wanting to split a string in BASH.  I know about gawk and maybe sed 
> but I'm looking for a less involved solution.  The simplest I've found 
> so far is the cut program but I'm wondering if there is something even 
> simpler.
> 
> To add some context, what surfaced this is I wanted to do an apropos on 
> all programs in my path.  What I have at this point is:
> 
> for i in `echo $PATH | cut -d: -f1-30 --output-delimiter=" "`; do
> for j in `ls -1 $i`; do apropos $j; read; done;
> done
> 

My solution:
echo "$PATH" | tr ':' ' ' | xargs ls -1 | xargs -n1 apropos -e





More information about the Discuss mailing list