| Author |
How to get parent dir in shell
|
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Hi all,
My PWD is /a/b/c and I want /a/b in shell variable.
Any idea about how to do this.
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Satish Chilukuri
Ranch Hand
Joined: Jun 23, 2005
Posts: 266
|
|
You can do it with bash parameter substitution:
You could also use sed:
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Worked Thanks a ton.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14487
|
|
|
There's also a "dirname" command. You'll see it used in a lot of scripts.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Tim Holloway wrote:There's also a "dirname" command.
Thanks Works, but I think it needs the full path, upto the file name
whereas,
|
 |
Craig Jackson
Ranch Hand
Joined: Mar 19, 2002
Posts: 405
|
|
My PWD is /a/b/c and I want /a/b in shell variable.
Another alternative is:
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
|
Craig, I used the same trick ;)
|
 |
 |
|
|
subject: How to get parent dir in shell
|
|
|