LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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

Tags used in this thread
Popular LQ Tags , , , , , , , , ,

Reply
 
Thread Tools
Old 06-22-2009, 04:27 AM   #16
rainbowbird
LQ Newbie
 
Registered: Apr 2009
Location: China, Shanghai
Distribution: Fedora 7
Posts: 2
Thanked: 0
a little modification


[Log in to get rid of this advertisement]
Quote:
Originally Posted by Disillusionist View Post
Code:
source="./tmp/myfile"
dest=~/.Waste/$(echo $source|sed "s@^./@$PWD@"|sed "s@^/@@")
Disillusionist:
a little modifiation
Code:
source="./tmp/myfile"
dest=~/.Waste/$(echo $source|sed "s@^./@$PWD/@"|sed "s@^/@@")
rainbowbird is offline     Reply With Quote
Old 09-07-2009, 03:34 PM   #17
kj6loh
Member
 
Registered: Jun 2004
Posts: 37
Thanked: 0
Quote:
Originally Posted by Andy Alkaline View Post
I'd like to be able to move the file into ~/.Waste/original/path

Using $PWD doesn't guarantee that. I need to have the absolute path of the file returned.

(a few minutes later)
Found it.
Bash equivalent for PHP realpath()
Unfortunately readlink is not on every bash system
macos kj6loh is offline     Reply With Quote
Old 11-02-2009, 07:55 PM   #18
edvalson
LQ Newbie
 
Registered: May 2009
Posts: 1
Thanked: 0
Quote:
What is your concern with using $PWD? If concerned about someone exporting variables to an incorrect value, you could always use $(pwd) to set the value of PWD.
Because if you write scripts using absolute paths that are not depending on a) where the script starts from, or b) from cd'ing somewhere inside the script, $PWD is irrelevant.

ta0kira has it right: to return the absolute path of a filename that is originally given with a relative path:

for example you are at a bash prompt in /dir1/dir2/dir3/dir4

and the file is /dir1/dir2/file1

ABSOLUTE_DIR=$(dirname $(readlink -f ../../dir2/file1))
linuxredhat edvalson is offline  
Tag This Post ,
Reply With Quote

Reply

Bookmarks


Thread Tools

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
ls - Do not list full path only filename baddah Linux - General 4 07-24-2008 05:58 AM
bash - return home path babag Programming 2 06-01-2008 05:59 PM
Getting the first part of a filename in a BASH script trevelluk Programming 3 02-15-2005 02:06 AM
php mail script return path richard22 Linux - Software 1 08-22-2003 05:10 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM


All times are GMT -5. The time now is 01:14 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration