![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2008
Posts: 8
Rep Power: 0
![]() |
Spaces in path names
Hello Everyone,
I am new here and just started shell scripting. I thought I would start with creating a shell script as a solution to one of my problems. I need some help with variables and path names (especially spaces in pathnames) here. I am trying to use my firefox bookmarks on linux with that on windows synchronously but I am getting errors with the path variable for the windows profile folder since it has spaces in its pathname. For Example: $ cd /mnt/hda1/Documents\ and\ Settings/ $ HDA1="/mnt/hda1/Documents\ and\ Settings/" $ cd $HDA1 bash: cd: /mnt/hda1/Documents\: No such file or directory With/out quotes, backslashes, all same.. I understand that shell does not like spaces. What should I write instead since I cannot change the pathname? Any suggestions please? Thank in advance
__________________
ESTRAGON: We've lost our rights? VLADIMIR: (distinctly) We got rid of them. |
|
|
|
|
|
#2 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 630
Rep Power: 4
![]() |
Re: Spaces in path names
bash Syntax (Toggle Plain Text)
Since everything is "encased" in the quotation marks, spaces shouldn't be a problem. ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Mar 2008
Posts: 8
Rep Power: 0
![]() |
Re: Spaces in path names
Quote:
![]() I already tried that but I am getting same thing.. ![]() $ HDA1="/mnt/hda1/Documents and Settings" $ cd $HDA1 bash: cd: /mnt/hda1/Documents: No such file or directory ![]()
__________________
ESTRAGON: We've lost our rights? VLADIMIR: (distinctly) We got rid of them. |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Spaces in path names
I'll take a whack at guessing:
HDA1="\"/mnt/hda1/Documents and Settings\"" Or: HDA1="/mnt/hda1/Documents\\ and\\ Settings" |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Mar 2008
Posts: 8
Rep Power: 0
![]() |
Re: Spaces in path names
Quote:
![]() $ HDA1="\"/mnt/hda1/Documents and Settings\"" $ echo $HDA1 "/mnt/hda1/Documents and Settings" $ cd $HDA1 bash: cd: "/mnt/hda1/Documents: No such file or directory $ HDA1="/mnt/hda1/Documents\\ and\\ Settings" $ echo $HDA1 /mnt/hda1/Documents\ and\ Settings $ cd $HDA1 bash: cd: /mnt/hda1/Documents\: No such file or directory Keep it coming please.. I am sure we will work this out by the sun rise.. ![]()
__________________
ESTRAGON: We've lost our rights? VLADIMIR: (distinctly) We got rid of them. |
|
|
|
|
|
|
#6 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Spaces in path names
It may have something to do with whether or not you're using single or double quotes if you have variables in your script somewhere that have a name in your directory path. If so, you will have to either use single quotes or use an escape character to ignore the variable. More Info
$ HDA1="\"/mnt/hda1/Documents and Settings\"" $ echo $HDA1 "/mnt/hda1/Documents and Settings" $ cd $HDA1 bash: cd: "/mnt/hda1/Documents: No such file or directory It may be since you are using HDA1 as a variable, and hda1 is in your path, that you may have to escape the hda1 to get it to work; or use single quotes. Last edited by Jabo; Mar 24th, 2008 at 8:04 PM. |
|
|
|
|
|
#7 | |
|
Newbie
Join Date: Mar 2008
Posts: 8
Rep Power: 0
![]() |
Re: Spaces in path names
Quote:
I tried all possible combinations with double quotes, single quote, slashs, backslash in defining the variable all same: linefeeds after space. I read that -1 (digit one, not lower L) parameter may prevent new line feed for ls command but I could not implement it to cp or mv commands ![]() Thanks for the link by the way .
__________________
ESTRAGON: We've lost our rights? VLADIMIR: (distinctly) We got rid of them. |
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 213
Rep Power: 3
![]() |
Re: Spaces in path names
a shot in the dark but change jessehks:
$ HDA1="/mnt/hda1/Documents and Settings" $ cd $HDA1 to: $ HDA1="/mnt/hda1/Documents and Settings" $ cd "$HDA1" ? has been a while since i've written a shell script |
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Mar 2008
Posts: 8
Rep Power: 0
![]() |
Re: Spaces in path names
Quote:
It worked! Thanks a lot. So the key was to use double quotes while calling the variable as well as while defining the variable, eh?! ![]() Thanks you all for your interest I will be right back ![]()
__________________
ESTRAGON: We've lost our rights? VLADIMIR: (distinctly) We got rid of them. |
|
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2008
Posts: 8
Rep Power: 0
![]() |
Re: Spaces in path names
I just wanted to share my final script which works just fine.
Since the installed add-ons are not compatible for both linux and windows at a time, using same profile folder with -ProfileManager was a bit of useless thus I really needed this thing: #!/bin/sh DATE=`date +%F-%H%M%S` HDA1="/mnt/hda1/Documents and Settings/username/Application Data/Mozilla/Firefox/Profiles/profile0.default" HDA6=/home/user/.mozilla/firefox/profile1.default mv -v $HDA6/bookmarks.html $HDA6/bookmarkbackups/bookmarks-$DATE.html cp -v "$HDA1"/bookmarks.html "$HDA1"/bookmarkbackups/bookmarks$DATE.html mv -v "$HDA1"/bookmarks.html $HDA6/bookmarks.html firefox cp -v $HDA6/bookmarks.html "$HDA1"/bookmarks.html I hope it is useful for somebody else out there too ![]()
__________________
ESTRAGON: We've lost our rights? VLADIMIR: (distinctly) We got rid of them. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing double spaces with str_replace | davil | PHP | 2 | Dec 12th, 2007 5:19 PM |
| adding csc to Path Environment | pr0gm3r | C# | 6 | Sep 9th, 2005 8:52 AM |
| seeking best path algorithm | lhk_mgtf2008 | Visual Basic | 9 | Jun 9th, 2005 8:11 PM |
| How create variables to hold directory names on Windows? | noleander | Bash / Shell Scripting | 5 | Mar 7th, 2005 10:18 AM |
| MYSQL, pipe delimited or just spaces? | scorpiosage | PHP | 0 | Feb 8th, 2005 3:32 AM |