Solved

split into an array?  ksh

Posted on 2006-07-03
4
795 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now