Solved

split into an array?  ksh

Posted on 2006-07-03
4
801 Views
Last Modified: 2013-12-26
want to split the path elements into an array.  Perl would be somehting like

@a = split /:/, $ENV{PATH};

How would you do this in ksh?  Is there a simple way to do this without awk, which I have never
used.

Thanks
0
Comment
Question by:hank1
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 17030989
Something like:

PATHARR=`echo $PATH | sed -e "s/:/ /g"`
set $PATHARR
echo "Count=$#"

Of course, if there are spaces in your pathelements you need to somehow manage these.
0
 
LVL 1

Author Comment

by:hank1
ID: 17031022
OK, I surrender.  How do you do this in awk?  There are spaces.
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 125 total points
ID: 17031042
Here - you can still do it in sh:

PATHARR=`echo $PATH | sed -e "s/ /___/g" -e "s/:/ /g"`
set $PATHARR
for DIR in $*
do
   echo "$DIR = `echo $DIR | sed -e 's/___/ /g'`"
done

0
 
LVL 1

Author Comment

by:hank1
ID: 17031056
OK OK you win.  But I'm going to ask for the awk version.  Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question