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, 02: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 02:47 PM.
 
Old 06-28-2009, 03:10 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
You have to put quotes around the value when you use it:
Code:
cd "$path"
 
Old 06-28-2009, 05: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 08:00 AM
Bash - passing text with spaces to functions jax8 Programming 2 04-19-2009 11:43 PM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
Escaping spaces in a variable Ransak Programming 3 02-10-2008 01:54 AM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM


All times are GMT -5. The time now is 07:39 PM.

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