Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bash Script to display directories in Path?

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
debut



Joined: Tue Nov 08, 2005 6:33 pm
Posts: 3

PostPosted: Wed Nov 09, 2005 7:59 pm    Post subject: Bash Script to display directories in Path? Reply with quote

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.
Back to top
View user's profile Send private message
Nobber
LXF regular


Joined: Mon Apr 11, 2005 4:24 pm
Posts: 370
Location: Nova Scotia

PostPosted: Wed Nov 09, 2005 9:39 pm    Post subject: RE: Bash Script to display directories in Path? Reply with quote

Try:

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

at the bash prompt.
_________________
800 LINES ERIC - GET BACK TO PYSKOOL
Back to top
View user's profile Send private message
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Wed Nov 09, 2005 9:43 pm    Post subject: RE: Bash Script to display directories in Path? Reply with quote

Try this command :
Code:
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.
Back to top
View user's profile Send private message
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Wed Nov 09, 2005 9:46 pm    Post subject: Re: RE: Bash Script to display directories in Path? Reply with quote

Nobber wrote:
Try:

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

at the bash prompt.


awk vs sed... a holy war to rival vi vs emacs Very Happy
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8454
Location: Warrington, UK

PostPosted: Thu Nov 10, 2005 12:26 am    Post subject: RE: Re: RE: Bash Script to display directories in Path? Reply with quote

There are two major differences with awk vs. sed

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

sed seems somewhat simpler for this particular operation.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Thu Nov 10, 2005 12:47 am    Post subject: Re: RE: Re: RE: Bash Script to display directories in Path? Reply with quote

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


OK, I'll give you that one Smile
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.
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8454
Location: Warrington, UK

PostPosted: Thu Nov 10, 2005 9:33 am    Post subject: RE: Re: RE: Re: RE: Bash Script to display directories in Pa Reply with quote

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)
Back to top
View user's profile Send private message
A-Wing
LXF regular


Joined: Tue Jul 05, 2005 8:25 pm
Posts: 460
Location: Wellingborough

PostPosted: Sun Nov 13, 2005 11:24 am    Post subject: RE: Re: RE: Re: RE: Bash Script to display directories in Pa Reply with quote

I use awk all the time simply because I have never tried to use sed, a bit like Nigel really Smile
_________________
Andrew Hutchings, Linux Jedi
www.a-wing.co.uk
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast