LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 06-28-2009, 03:43 PM   #1
aolong
Member
 
Registered: Aug 2006
Location: US
Distribution: Debian, CentOS
Posts: 40

Rep: Reputation: 15
passing variable (a path) with spaces


OK, I searched the forums and read that this should work, but it fails...

path="/media/My Passport"
cd $path
ls .

returns "./dupes.sh: line 19: cd: /media/My: No such file or directory"

but, if I escape the space it still fails:

path="/media/My\ Passport"

I have tried all variations I can think of without success... renaming the dir, mounting differently, or linking are not options, I need to deal with paths with spaces...

Andrew

Last edited by aolong; 06-28-2009 at 03:47 PM.
 
Old 06-28-2009, 04:10 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You have to put quotes around the value when you use it:
Code:
cd "$path"
 
Old 06-28-2009, 06:50 PM   #3
aolong
Member
 
Registered: Aug 2006
Location: US
Distribution: Debian, CentOS
Posts: 40

Original Poster
Rep: Reputation: 15
Thank you. That works.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: Passing arrays with spaces jakeo25 Programming 8 06-05-2009 09:00 AM
Bash - passing text with spaces to functions jax8 Programming 2 04-20-2009 12:43 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 06:48 PM
Escaping spaces in a variable Ransak Programming 3 02-10-2008 02:54 AM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 03:18 PM


All times are GMT -5. The time now is 11:41 AM.

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