BASH Programming: spaces ignored
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > BASH Programming: spaces ignored




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    BASH Programming: spaces ignored  
sean@mail.capitalgenomix.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 10: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





[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
shakahshakah@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 10: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"






[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 10: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.





[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 10: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





[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
Hartmut Holzgraefe


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 10: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





[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
Kenny McCormack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-30-05 10:52 PM

In article <yw1xwtpgkbfa.fsf@ford.inprovide.com>,
examnotes  <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$






[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
alexs


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-05 11:03 PM



Kenny McCormack wrote:
> In article <yw1xwtpgkbfa.fsf@ford.inprovide.com>,
> examnotes  <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$

:-)






[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
Fao, Sean


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-05 11: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





[ Post a follow-up to this message ]



    Re: BASH Programming: spaces ignored  
Fao, Sean


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-05 11: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:17 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register