ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
The first time I tried just using the variable containing an unescaped pathname, the 2nd time I tried excaping the /'s in the pathname. Both times, though, I get the same error message.
Hmm, and that works...just not far enough. I realize that I gave a bad example when I first posted, though.
Given a directory /home/me/temp/subdir, that has a couple of files in it;
And given a subdirectory listing, such as would be returned from ls -Ra:
./subdir:
file1
file2
I want to get the fully-qualified pathname of file1 and file2. So what I figure I could do is take "./subdir:", get rid of the ":" with
Code:
for i in `ls -Ra`; do
if [[ "$i" == *: ]]; then
dirname=`echo $i | sed -e s/://g`
and then replace the "./" with the real pathname, which is /home/me/temp, giving me
/home/me/temp/subidir..which I could then concatenate onto 'file1' and 'file2' when I needed them.
The problem with your first example is the content of the pwd command: It holds forward slashes, this will confuse sed (forward slash being the normal seperator).
Change the seperator and you'll be ok. Also, the . and g can go. The searchstring should be \.
You might also like to get the current working directory with /bin/pwd instead of the shell builtin so you get the real path, unwound of symlinks.
BTW, you can use pretty much any punctuation character as the separator, so you can tailor the sed command appropriately to minimise the amount of character escaping you have to do.
Last edited by eddiebaby1023; 05-23-2005 at 05:03 PM.
Yeah, the problem with using just pwd is that I need to get the full path of a directory that I'm not actually in, so it had to be 'pwd' + 'relative path of the directory I'm interested in minus the ./ and ending /'
And using sed like that is quite nifty, I'm glad to know of it!
Originally posted by rose_bud4201 Yeah, the problem with using just pwd is that I need to get the full path of a directory that I'm not actually in, so it had to be 'pwd' + 'relative path of the directory I'm interested in minus the ./ and ending /'
No, you misunderstood what I was saying about "pwd". The shell builtin will show you path you used to get to your current directory, /bin/pwd will show you the real path to it. To demonstrate, "cd /tmp; ln -s /tmp tempo; cd tempo". Then run "pwd", and "/bin/pwd" and spot the difference.
hmm, interesting. I figured out how to solve the problem awhile ago, but this is worth remembering. I'm constantly up against this at work, where I've got directory symlinks all over the freakin' place
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.