|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I want to define a variable pointing to my desktop location, in bash I say
desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" When I echo it looks ok, and yet when I input cd $desktop it complaints that there is no /cygdrive/c/Dokumente directory. wtf? I also tried defining desktop using '\ ', that is desktop="/cygdrive/c/Dokumente\\ und\\ Ein... I do it obviously in cygwin bash, and I don't know if it would work on Linux. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Luntain <news.20.luntain@spamgourmet.com> wrote:
> I want to define a variable pointing to my desktop location, in bash I say > > desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" > > When I echo it looks ok, and yet when I input cd $desktop it complaints If the value of a variable contains whitespace, you must quote the variable name when you reference it, if you want shell to treat it as a single argument. Otherwise, shell interprets the spaces as argument delimiters. This means, cd $desktop is interpreted as a cd command with three arguments: cd "/cygdrive/c/Dokumente" "und" "Einstellungen/Luntain/Desktop" The cd command uses a single argument, so it will attempt to change your working directory to /cygdrive/c/Dokumente, which does not exist. If you surround the referenced variable name with double quotes, cd "$desktop" the shell will preserve the spaces and interpret this as a cd command with a single argument cd "/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop" which is what you desire. -- Kenan Kalajdzic |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
>> I want to define a variable pointing to my desktop location, in bash I say
>> >> desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" >> >> When I echo it looks ok, and yet when I input cd $desktop it complaints > > If the value of a variable contains whitespace, you must quote the > variable name when you reference it, if you want shell to treat it > as a single argument. Otherwise, shell interprets the spaces as > argument delimiters. > > This means, > > cd $desktop > > is interpreted as a cd command with three arguments: > > cd "/cygdrive/c/Dokumente" "und" "Einstellungen/Luntain/Desktop" > > The cd command uses a single argument, so it will attempt to change > your working directory to /cygdrive/c/Dokumente, which does not exist. > If you surround the referenced variable name with double quotes, > > cd "$desktop" > > the shell will preserve the spaces and interpret this as a cd command > with a single argument > > cd "/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop" > > which is what you desire. > I am not that lame not to now that spaces seperate arguments. I would like to point out that I assign a quoted string to desktop variable: desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" when I echo $desktop, the path is displayes with the enclosing quotes. I don't understand why cd doesn't seem to see the quotes. I want to have a quick way of changing to my desktop directory, this is the hole point of that desktop variable. There must be a way. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2007-11-10, Luntain <news.20.luntain@spamgourmet.com> wrote:
> > I am not that lame not to now that spaces seperate arguments. > > I would like to point out that I assign a quoted string to desktop variable: > > desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" > > when I echo $desktop, the path is displayes with the enclosing quotes. I > don't understand why cd doesn't seem to see the quotes. I want to have a > quick way of changing to my desktop directory, this is the hole point of > that desktop variable. There must be a way. cd "$desktop" is one way. Another way is to use the CDPATH variable. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 2007-11-10, Luntain <news.20.luntain@spamgourmet.com> wrote:
> > desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" > > when I echo $desktop, the path is displayes with the enclosing quotes. This is the expected behaviour. You can have a directory with a name like: abc"xyz in that case, you can cd in this way: cd abc\"xyz try: desktop="bla bla bla with as many / as you want" But the \ is the scape character (special meaning). If you want a \ without special meaning, use \\ > I > don't understand why cd doesn't seem to see the quotes. I want to have a > quick way of changing to my desktop directory, this is the hole point of > that desktop variable. There must be a way. try just: cd Best regards, Claudio. (I apologize my bad english) |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 2007-11-10, Luntain wrote:
> > I want to define a variable pointing to my desktop location, in bash I say > > desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" > > When I echo it looks ok, and yet when I input cd $desktop it complaints > that there is no /cygdrive/c/Dokumente directory. wtf? I also tried > defining desktop using '\ ', that is > > desktop="/cygdrive/c/Dokumente\\ und\\ Ein... > > I do it obviously in cygwin bash, and I don't know if it would work on > Linux. The quotes are not part of the path; remove them. desktop="/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop" When you use it, quote the variable, e.g.: cd "$desktop" -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
In article <AyjZi.45383$c_1.39330@text.news.blueyonder.co.uk> ,
Luntain <news.20.luntain@spamgourmet.com> wrote: > I would like to point out that I assign a quoted string to desktop variable: > > desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" > > when I echo $desktop, the path is displayes with the enclosing quotes. I > don't understand why cd doesn't seem to see the quotes. I want to have a > quick way of changing to my desktop directory, this is the hole point of > that desktop variable. There must be a way. Quote processing is not performed on the result of variable expansion. So it's looking for a filename that actually starts with doublequote. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
>> I am not that lame not to now that spaces seperate arguments.
>> >> I would like to point out that I assign a quoted string to desktop variable: >> >> desktop="\"/cygdrive/c/Dokumente und Einstellungen/Luntain/Desktop\"" >> >> when I echo $desktop, the path is displayes with the enclosing quotes. I >> don't understand why cd doesn't seem to see the quotes. I want to have a >> quick way of changing to my desktop directory, this is the hole point of >> that desktop variable. There must be a way. > > cd "$desktop" is one way. Another way is to use the CDPATH variable. CDPATH is what I need, thx. CDPATH=".:/cygdrive/c/Dokumente und Einstellungen/Luntain" |
|
![]() |
| Outils de la discussion | |
|
|