LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   expanding ../.. sigils in a shell script? (https://www.linuxquestions.org/questions/programming-9/expanding-sigils-in-a-shell-script-574647/)

ocicat 08-04-2007 01:41 AM

expanding ../.. sigils in a shell script?
 
I am writing a Bourne shell script which takes a directory name as an argument. It would be good if the pathname is absolute, and I handle the obvious ~, ~/subdir, ., ./subdir, .., & ../subdir possibilities fine.

However, legitimate relative directory names such as ../.., ../../subdir, ../../../subdir are especially thorny. Is there some obvious way of converting these to absolute pathnames available without me having to manually step through the pathname right-to-left substituting as I go along?

Any insight would be appreciated. Thanks.

raskin 08-04-2007 02:20 AM

Did you try 'a=$(cd $dir ; pwd)' ? This command should remain in the same directory, but put absolute variant of $dir to $a.

ocicat 08-04-2007 12:55 PM

Quote:

Originally Posted by raskin
Did you try 'a=$(cd $dir ; pwd)' ?

This is very cool! Thanks!


All times are GMT -5. The time now is 03:37 PM.