LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 11-12-2010, 11:11 AM   #1
mkohler
LQ Newbie
 
Registered: Nov 2010
Posts: 17

Rep: Reputation: 0
relative/absolute paths?


Hi,

I am creating a script and the script will move files to a specified directory. I want the user to be able to enter relative or absolute path names but how can I store the original directory this way? I have tried this :

path=`pwd`
if [ $1=$path* ]; then
echo $1 >> /root/.../pathName.txt
mv $1 /root/.../
else
echo `pwd`/$1 >> /root/.../pathName.txt
mv $1 /root/.../
fi

no matter whether I type a relative or absolute path name I always meet the condition at the start

Thanks for any help!
 
Old 11-12-2010, 01:12 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,028
Blog Entries: 5

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
You have an extraneous asterisk in the test "$path*" - it should just be "$path".

There should be spaces around your equal sign - it may be thinking you're trying to set the variable there rather than doing a test. (Setting a variable would likely always succeed so it would always meet the condition it thinks you're testing for rather than the one you think it is). It should be:
if [ $1 = $path ]

Last edited by MensaWater; 11-12-2010 at 01:15 PM.
 
Old 11-12-2010, 04:55 PM   #3
mkohler
LQ Newbie
 
Registered: Nov 2010
Posts: 17

Original Poster
Rep: Reputation: 0
tried that but doesnt seem to work i just want to write the original pathname of the file im moving to a text file
cant get it to work any other ideas?
 
Old 11-13-2010, 04:45 AM   #4
martinbc
Member
 
Registered: Jun 2010
Distribution: Ubuntu, played with Puppy Slitaz & OpenSUSE
Posts: 40

Rep: Reputation: 4
Hi

If you set path with
Code:
path=`pwd`"*"
and modify your if line to
Code:
if [[ $1 =~ $path ]]; then
that might work (but not with a filename of ./filename)

The =~ performs a regex comparison

Martin
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash: ln and relative paths tortle Programming 8 05-10-2010 06:50 AM
Absolute and relative paths Gins Linux - General 6 11-08-2008 09:48 PM
relative to absolute path vishalbutte Programming 4 01-14-2006 04:17 PM
periods in relative paths? kuplo Linux - Newbie 2 01-10-2006 06:19 AM
relative/absolute paths in Java djgerbavore Programming 2 10-26-2004 09:01 PM


All times are GMT -5. The time now is 06:10 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration