Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

split into an array?  ksh

Posted on 2006-07-03
4
Medium Priority
?
827 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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