Bash Script to display directories in Path?

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Bash Script to display directories in Path?

Postby debut » Wed Nov 09, 2005 7:59 pm

Hello there,

As a newbie:

The directories in PATH can be hard to distinguish when printed out as
one line with colon .Please, can i have a sample script to display
them,one to a line.

Thank you.
debut
 
Posts: 3
Joined: Tue Nov 08, 2005 6:33 pm

RE: Bash Script to display directories in Path?

Postby Nobber » Wed Nov 09, 2005 9:39 pm

Try:

echo $PATH | sed 's/:/\n/g'

at the bash prompt.
800 LINES ERIC - GET BACK TO PYSKOOL
User avatar
Nobber
LXF regular
 
Posts: 370
Joined: Mon Apr 11, 2005 3:24 pm
Location: Nova Scotia

RE: Bash Script to display directories in Path?

Postby Nigel » Wed Nov 09, 2005 9:43 pm

Try this command :
Code: Select all
echo $PATH | awk -F: '{for (i=1; i<=NF; i++) print $i}'


note that the outer brackets are curly ones, the inner ones are standard brackets, the quotes are standard single quotes.
Hope this helps,

Nigel.
User avatar
Nigel
LXF regular
 
Posts: 1141
Joined: Fri Apr 08, 2005 8:03 pm
Location: Gloucestershire, UK

Re: RE: Bash Script to display directories in Path?

Postby Nigel » Wed Nov 09, 2005 9:46 pm

Nobber wrote:Try:

echo $PATH | sed 's/:/\n/g'

at the bash prompt.


awk vs sed... a holy war to rival vi vs emacs :D
User avatar
Nigel
LXF regular
 
Posts: 1141
Joined: Fri Apr 08, 2005 8:03 pm
Location: Gloucestershire, UK

RE: Re: RE: Bash Script to display directories in Path?

Postby nelz » Thu Nov 10, 2005 12:26 am

There are two major differences with awk vs. sed

1) You can use both
2) you can admit to using both :)

sed seems somewhat simpler for this particular operation.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8504
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Re: RE: Re: RE: Bash Script to display directories in Path?

Postby Nigel » Thu Nov 10, 2005 12:47 am

nelz wrote:sed seems somewhat simpler for this particular operation.


OK, I'll give you that one :)
Maybe it's just the people I used to work with that got polarised with one or the other. I used awk a bit, never got around to learning sed.
User avatar
Nigel
LXF regular
 
Posts: 1141
Joined: Fri Apr 08, 2005 8:03 pm
Location: Gloucestershire, UK

RE: Re: RE: Re: RE: Bash Script to display directories in Pa

Postby nelz » Thu Nov 10, 2005 9:33 am

I'm the other way around. I know sed reasonably ell and rarely use awk. awk looks a lot more powerful, but I need to read the man pages again whenever I want to use it.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8504
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

RE: Re: RE: Re: RE: Bash Script to display directories in Pa

Postby A-Wing » Sun Nov 13, 2005 11:24 am

I use awk all the time simply because I have never tried to use sed, a bit like Nigel really :)
Andrew Hutchings, Linux Jedi
http://www.a-wing.co.uk
User avatar
A-Wing
LXF regular
 
Posts: 460
Joined: Tue Jul 05, 2005 7:25 pm
Location: Wellingborough


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests