| Author |
BASH Programming: spaces ignored
|
|
| sean@mail.capitalgenomix.com 2005-05-30, 5:52 pm |
| I'm having difficulty with a BASH script that I'm attempting to write.
I'm attempting to change directories to a path with a space in the name
and it appears that the spaces are being dropped. Following is the
script:
#!/bin/bash
fileserver_path="/mnt/fs/Documents/DS\ -\ Datasheets/"
cd $fileserver_path
if [ "$?" != "0" ]; then
echo Cannot locate $fileserver_path
exit 1
fi
The following error occurs with this script:
../script: line 4: cd: /mnt/fs/Documents/DS\: No such file or directory
As you can see, the spaces are being ignored. I've tried everything I
could think of to get it to stop ignoring the spaces; however, I've been
quite unsuccessful.
Can anybody please give me some advise? I'm quite new to BASH
programming so it's quite possible that I'm going about this the wrong
way. If I am, feel free to provide any advise.
Thank you advance,
--
Sean
| |
| shakahshakah@gmail.com 2005-05-30, 5:52 pm |
| sean@mail.capitalgenomix.com wrote:
> I'm having difficulty with a BASH script that I'm attempting to write.
> I'm attempting to change directories to a path with a space in the name
> and it appears that the spaces are being dropped. Following is the
> script:
>
> #!/bin/bash
> fileserver_path="/mnt/fs/Documents/DS\ -\ Datasheets/"
>
> cd $fileserver_path
>
> if [ "$?" != "0" ]; then
> echo Cannot locate $fileserver_path
> exit 1
> fi
>
> The following error occurs with this script:
>
> ./script: line 4: cd: /mnt/fs/Documents/DS\: No such file or directory
>
> As you can see, the spaces are being ignored. I've tried everything I
> could think of to get it to stop ignoring the spaces; however, I've been
> quite unsuccessful.
>
> Can anybody please give me some advise? I'm quite new to BASH
> programming so it's quite possible that I'm going about this the wrong
> way. If I am, feel free to provide any advise.
>
> Thank you advance,
>
> --
> Sean
Does the following work for you?
cd "$fileserver_path"
| |
| Paul Pluzhnikov 2005-05-30, 5:52 pm |
| sean@mail.capitalgenomix.com writes:
> Can anybody please give me some advise?
Read this: http://www.tldp.org/LDP/abs/html/quoting.html
> ing so it's quite possible that I'm going about this the wrong
> way.
You are. Here is your script fixed:
#!/bin/bash
fileserver_path="/mnt/fs/Documents/DS - Datasheets/"
cd "$fileserver_path"
if [ "$?" != "0" ]; then
echo Cannot locate \"$fileserver_path\"
exit 1
fi
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| Måns Rullgård 2005-05-30, 5:52 pm |
| "shakahshakah@gmail.com" <shakahshakah@gmail.com> writes:
> sean@mail.capitalgenomix.com wrote:
>
> Does the following work for you?
> cd "$fileserver_path"
Always quote string with variables in them, no exceptions. In this
case, you get a harmless failure. Another time, you might end up
wiping out half your data by mistake.
--
Måns Rullgård
mru@inprovide.com
| |
| Hartmut Holzgraefe 2005-05-30, 5:52 pm |
| sean@mail.capitalgenomix.com wrote:
> #!/bin/bash
> fileserver_path="/mnt/fs/Documents/DS\ -\ Datasheets/"
>
> cd $fileserver_path
try this instead:
fileserver_path="/mnt/fs/Documents/DS - Datasheets/"
cd "$fileserver_path"
--
Hartmut Holzgraefe, Senior Support Engineer .
MySQL AB, www.mysql.com
| |
| Kenny McCormack 2005-05-30, 5:52 pm |
| In article <yw1xwtpgkbfa.fsf@ford.inprovide.com>,
=?iso-8859-1?q?M=E5ns_Rullg=E5rd?= <mru@inprovide.com> wrote:
....
>Always quote string with variables in them, no exceptions. In this
bash$ foo="echo this is a test"
bash$ $foo that proves that there are exceptions to every rule
this is a test that proves that there are exceptions to every rule
bash$
| |
|
|
Kenny McCormack wrote:
> In article <yw1xwtpgkbfa.fsf@ford.inprovide.com>,
> =?iso-8859-1?q?M=E5ns_Rullg=E5rd?= <mru@inprovide.com> wrote:
> ...
>
> bash$ foo="echo this is a test"
> bash$ $foo that proves that there are exceptions to every rule
> this is a test that proves that there are exceptions to every rule
> bash$
:-)
| |
| Fao, Sean 2005-05-31, 6:03 pm |
| shakahshakah@gmail.com wrote:
> Does the following work for you?
> cd "$fileserver_path"
>
That worked perfectly. Thank you! And I also learned something new out
of this!
--
Sean
| |
| Fao, Sean 2005-05-31, 6:03 pm |
| Paul Pluzhnikov wrote:
> sean@mail.capitalgenomix.com writes:
>
>
>
>
> Read this: http://www.tldp.org/LDP/abs/html/quoting.html
That's a great link. Thanks for that!
>
>
> You are. Here is your script fixed:
>
> #!/bin/bash
> fileserver_path="/mnt/fs/Documents/DS - Datasheets/"
>
> cd "$fileserver_path"
> if [ "$?" != "0" ]; then
> echo Cannot locate \"$fileserver_path\"
> exit 1
> fi
Funny how I tried so many different things; but never tried putting
quotes around the path on the cd line, as I always do in at a command
prompt. Oh well; I'll know for next time.
Thank you for the info,
--
Sean
|
|
|
|