Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: 0
relative/absolute paths?


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 :

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

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, 12:12 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,986
Blog Entries: 14

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
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 12:15 PM.
Old 11-12-2010, 03:55 PM   #3
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, 03:45 AM   #4
Registered: Jun 2010
Distribution: Ubuntu, played with Puppy Slitaz & OpenSUSE
Posts: 40

Rep: Reputation: 4

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

The =~ performs a regex comparison



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

All times are GMT -5. The time now is 05:19 AM.

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