Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a program that takes a relative path as input appends it to a some path string to get the actual path.

Now all I can input is the relative path. So if I want to go one level above my input will be ../mypath.

If I know the depth of the path used internally, I can use .. as many times to go to the root directory and then give the absolute path. But suppose I do not know the depth of the directory, can I construct a relative path string such that it considers it as a relative path. One way could be to have enough .. in the path string so that I can force an absolute path for some maximum depth of path.

Is there some path string syntax that I am not aware of but can achieve this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Perhaps something like this:

s="."; until [[ $(readlink -e $s) == / ]]; do s+=/..; done; echo "$s"; ls -l "$s"
share|improve this answer

If the program always defaults to the same location, just make a symlink in that directory to / and use that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.