[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

split into an array?  ksh

Posted on 2006-07-03
4
Medium Priority
?
830 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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. …
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 quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

872 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