| View previous topic :: View next topic |
| Author |
Message |
debut
Joined: Tue Nov 08, 2005 6:33 pm Posts: 3
|
Posted: Wed Nov 09, 2005 7:59 pm Post subject: Bash Script to display directories in Path? |
|
|
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 |
|
 |
Nobber LXF regular

Joined: Mon Apr 11, 2005 4:24 pm Posts: 370 Location: Nova Scotia
|
Posted: Wed Nov 09, 2005 9:39 pm Post subject: RE: Bash Script to display directories in Path? |
|
|
Try:
echo $PATH | sed 's/:/\n/g'
at the bash prompt. _________________ 800 LINES ERIC - GET BACK TO PYSKOOL |
|
| Back to top |
|
 |
Nigel LXF regular

Joined: Fri Apr 08, 2005 9:03 pm Posts: 1141 Location: Gloucestershire, UK
|
Posted: Wed Nov 09, 2005 9:43 pm Post subject: RE: Bash Script to display directories in Path? |
|
|
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 |
|
 |
Nigel LXF regular

Joined: Fri Apr 08, 2005 9:03 pm Posts: 1141 Location: Gloucestershire, UK
|
Posted: Wed Nov 09, 2005 9:46 pm Post subject: Re: RE: Bash Script to display directories in Path? |
|
|
| Nobber wrote: | Try:
echo $PATH | sed 's/:/\n/g'
at the bash prompt. |
awk vs sed... a holy war to rival vi vs emacs  |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 8036 Location: Warrington, UK
|
Posted: Thu Nov 10, 2005 12:26 am Post subject: RE: Re: RE: Bash Script to display directories in Path? |
|
|
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) |
|
| Back to top |
|
 |
Nigel LXF regular

Joined: Fri Apr 08, 2005 9:03 pm Posts: 1141 Location: Gloucestershire, UK
|
Posted: Thu Nov 10, 2005 12:47 am Post subject: Re: RE: Re: RE: Bash Script to display directories in Path? |
|
|
| 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. |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 8036 Location: Warrington, UK
|
Posted: Thu Nov 10, 2005 9:33 am Post subject: RE: Re: RE: Re: RE: Bash Script to display directories in Pa |
|
|
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 |
|
 |
A-Wing LXF regular

Joined: Tue Jul 05, 2005 8:25 pm Posts: 460 Location: Wellingborough
|
Posted: Sun Nov 13, 2005 11:24 am Post subject: RE: Re: RE: Re: RE: Bash Script to display directories in Pa |
|
|
I use awk all the time simply because I have never tried to use sed, a bit like Nigel really  _________________ Andrew Hutchings, Linux Jedi
www.a-wing.co.uk |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|