LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2007, 01:41 AM   #1
ocicat
Member
 
Registered: May 2007
Posts: 208

Rep: Reputation: 48
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.
 
Old 08-04-2007, 02:20 AM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Did you try 'a=$(cd $dir ; pwd)' ? This command should remain in the same directory, but put absolute variant of $dir to $a.
 
Old 08-04-2007, 12:55 PM   #3
ocicat
Member
 
Registered: May 2007
Posts: 208

Original Poster
Rep: Reputation: 48
Quote:
Originally Posted by raskin
Did you try 'a=$(cd $dir ; pwd)' ?
This is very cool! Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script for expanding lines in a file b123coder Programming 1 05-25-2006 04:51 AM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 05:05 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 05:17 PM
Expanding file names in a script? ../blah -> /home/blah Bebo Linux - General 24 03-29-2004 05:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration