aspose file tools*
The moose likes Linux / UNIX and the fly likes How to get parent dir in shell Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to get parent dir in shell" Watch "How to get parent dir in shell" New topic
Author

How to get parent dir in shell

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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: 2902
    
    1

Satish Chilukuri wrote:You can do it with bash parameter substitution:

Worked Thanks a ton.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

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: 2902
    
    1

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: 2902
    
    1

Craig, I used the same trick ;)
 
Don't get me started about those stupid light bulbs.
 
subject: How to get parent dir in shell