Stupid spaces

Stupid spaces

am 19.07.2004 15:29:45 von Calin Cosma

Hello all.

I know the following question is a dumb one, but I've tried to make a
script working and I'm stuck.

I'll try to isolate the problem as follows.

I have a script which at some moment during the execution, needs to cd.
So I assumed that the following would work:


file_path='"/some/where/Test Folder/"'
echo "$file_path"
cd "$file_path"

But surprise: it didn't. Every time I try to run it it gives me
something like:


$ ./cding.sh
"/some/where/Test Folder/"
../cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
directory
$

although the Test Folder exist, is in the right path (/some/where/Test
Folder) and it's permissions are 777.

Any idea?

TIA

Calin Cosma



------------------------------------------------------------ ---
Incearca acum noul sistem de dating oferit de portalul acasa.ro

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 19.07.2004 15:56:14 von cditrani

file_path='test foo'
cd "$file_path"

On Mon, 2004-07-19 at 09:29, calin wrote:
> Hello all.
>
> I know the following question is a dumb one, but I've tried to make a
> script working and I'm stuck.
>
> I'll try to isolate the problem as follows.
>
> I have a script which at some moment during the execution, needs to cd.
> So I assumed that the following would work:
>
>
> file_path='"/some/where/Test Folder/"'
> echo "$file_path"
> cd "$file_path"
>
> But surprise: it didn't. Every time I try to run it it gives me
> something like:
>
>
> $ ./cding.sh
> "/some/where/Test Folder/"
> ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
> directory
> $
>
> although the Test Folder exist, is in the right path (/some/where/Test
> Folder) and it's permissions are 777.
>
> Any idea?
>
> TIA
>
> Calin Cosma
>
>
>
> ------------------------------------------------------------ ---
> Incearca acum noul sistem de dating oferit de portalul acasa.ro
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 19.07.2004 16:45:12 von Scott Taylor

calin said:
>
> Hello all.
>
> file_path='"/some/where/Test Folder/"'
> echo "$file_path"
> cd "$file_path"
>
> But surprise: it didn't. Every time I try to run it it gives me
> something like:
>
>
> $ ./cding.sh
> "/some/where/Test Folder/"
> ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
> directory
> $
>
> although the Test Folder exist, is in the right path (/some/where/Test
> Folder) and it's permissions are 777.

It's not lying to you. The directory "/some/where/Test Folder/" doesn't
exist, but I bet /some/where/Test Folder/ does. Remove all ' and " from
your script and watch it work.

Enjoy.

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 19.07.2004 16:52:27 von Scott Taylor

Scott Taylor said:
>
> calin said:
>>
>> Hello all.
>>
>> file_path='"/some/where/Test Folder/"'

Oops, sorry, you do need quotes, but only " not '
file_path="/some/where/Test Folder/"



>> echo "$file_path"
>> cd "$file_path"
>>
>> But surprise: it didn't. Every time I try to run it it gives me
>> something like:
>>
>>
>> $ ./cding.sh
>> "/some/where/Test Folder/"
>> ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
>> directory
>> $
>>
>> although the Test Folder exist, is in the right path (/some/where/Test
>> Folder) and it's permissions are 777.
>
> It's not lying to you. The directory "/some/where/Test Folder/" doesn't
> exist, but I bet /some/where/Test Folder/ does. Remove all ' and " from
> your script and watch it work.
>
> Enjoy.
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>


--
Scott

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 19.07.2004 16:59:52 von Calin Cosma

Worked just great. Thank you all.



On Mon, 2004-07-19 at 16:56, Chris DiTrani wrote:
> file_path='test foo'
> cd "$file_path"
>
> On Mon, 2004-07-19 at 09:29, calin wrote:
> > Hello all.
> >
> > I know the following question is a dumb one, but I've tried to make a
> > script working and I'm stuck.
> >
> > I'll try to isolate the problem as follows.
> >
> > I have a script which at some moment during the execution, needs to cd.
> > So I assumed that the following would work:
> >
> >
> > file_path='"/some/where/Test Folder/"'
> > echo "$file_path"
> > cd "$file_path"
> >
> > But surprise: it didn't. Every time I try to run it it gives me
> > something like:
> >
> >
> > $ ./cding.sh
> > "/some/where/Test Folder/"
> > ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
> > directory
> > $
> >
> > although the Test Folder exist, is in the right path (/some/where/Test
> > Folder) and it's permissions are 777.
> >
> > Any idea?
> >
> > TIA
> >
> > Calin Cosma
> >
> >
> >
> > ------------------------------------------------------------ ---
> > Incearca acum noul sistem de dating oferit de portalul acasa.ro
> >
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
> ------------------------------------------------------------ ---
> Incearca acum noul sistem de dating oferit de portalul acasa.ro
>
>



------------------------------------------------------------ ---
Incearca acum noul sistem de dating oferit de portalul acasa.ro

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 20.07.2004 19:48:44 von scohen

instead of the echo do an ls and see what it says.

Steve Cohen

On Mon, 19 Jul 2004, calin wrote:

>
> Hello all.
>
> I know the following question is a dumb one, but I've tried to make a
> script working and I'm stuck.
>
> I'll try to isolate the problem as follows.
>
> I have a script which at some moment during the execution, needs to cd.
> So I assumed that the following would work:
>
>
> file_path='"/some/where/Test Folder/"'
> echo "$file_path"
> cd "$file_path"
>
> But surprise: it didn't. Every time I try to run it it gives me
> something like:
>
>
> $ ./cding.sh
> "/some/where/Test Folder/"
> ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
> directory
> $
>
> although the Test Folder exist, is in the right path (/some/where/Test
> Folder) and it's permissions are 777.
>
> Any idea?
>
> TIA
>
> Calin Cosma
>
>
>
> ------------------------------------------------------------ ---
> Incearca acum noul sistem de dating oferit de portalul acasa.ro
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 20.07.2004 19:55:09 von scohen

Also,

You are using way to many quotes. Just write this:

file_path="/some/where/Test Folder/"
echo $file_path
cd $file_path

You already quoted the path once. There is no need for the quotes around
the variable and there is no need for the single and double quotes around
the path.

Also, put in a pwd after the cd so you can see where you are as a test.

Steve Cohen


On Mon, 19 Jul 2004, calin wrote:

>
> Hello all.
>
> I know the following question is a dumb one, but I've tried to make a
> script working and I'm stuck.
>
> I'll try to isolate the problem as follows.
>
> I have a script which at some moment during the execution, needs to cd.
> So I assumed that the following would work:
>
>
> file_path='"/some/where/Test Folder/"'
> echo "$file_path"
> cd "$file_path"
>
> But surprise: it didn't. Every time I try to run it it gives me
> something like:
>
>
> $ ./cding.sh
> "/some/where/Test Folder/"
> ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
> directory
> $
>
> although the Test Folder exist, is in the right path (/some/where/Test
> Folder) and it's permissions are 777.
>
> Any idea?
>
> TIA
>
> Calin Cosma
>
>
>
> ------------------------------------------------------------ ---
> Incearca acum noul sistem de dating oferit de portalul acasa.ro
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 20.07.2004 20:20:31 von cditrani

On Tue, 2004-07-20 at 13:55, scohen wrote:
> Also,
>
> You are using way to many quotes. Just write this:
>
> file_path="/some/where/Test Folder/"
> echo $file_path
> cd $file_path
>

Did you actually try this? Doesn't work in my shell. I'm sure he tried
this first and only got more complicated when it failed to work.

In your above example $file_path is an unquoted string that turns into
two args, '/some/where/Test' and 'Folder/', when expanded and passed to
cd.

CD

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 20.07.2004 20:22:44 von Adam Lang

Why the quotes?

[root@ford /home]# file_path="/root"
[root@ford /home]# echo $file_path
/root
[root@ford /home]# cd $file_path
[root@ford /root]#

Remember, most of the script stuff you can test on the command line.

----- Original Message -----
From: "scohen"
To: "calin"
Cc:
Sent: Tuesday, July 20, 2004 1:48 PM
Subject: Re: Stupid spaces


> instead of the echo do an ls and see what it says.
>
> Steve Cohen
>
> On Mon, 19 Jul 2004, calin wrote:
>
> >
> > Hello all.
> >
> > I know the following question is a dumb one, but I've tried to make a
> > script working and I'm stuck.
> >
> > I'll try to isolate the problem as follows.
> >
> > I have a script which at some moment during the execution, needs to cd.
> > So I assumed that the following would work:
> >
> >
> > file_path='"/some/where/Test Folder/"'
> > echo "$file_path"
> > cd "$file_path"
> >
> > But surprise: it didn't. Every time I try to run it it gives me
> > something like:
> >
> >
> > $ ./cding.sh
> > "/some/where/Test Folder/"
> > ./cding.sh: line 5: cd: "/some/where/Test Folder/": No such file or
> > directory
> > $
> >
> > although the Test Folder exist, is in the right path (/some/where/Test
> > Folder) and it's permissions are 777.
> >
> > Any idea?
> >
> > TIA
> >
> > Calin Cosma
> >
> >
> >
> > ------------------------------------------------------------ ---
> > Incearca acum noul sistem de dating oferit de portalul acasa.ro
> >
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-admin"
in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 20.07.2004 20:37:59 von Adam Lang

oooooh

The catch is the space ... didn't even notice

Need to retest :p
----- Original Message -----
From: "Chris DiTrani"
To: "scohen"
Cc:
Sent: Tuesday, July 20, 2004 2:20 PM
Subject: Re: Stupid spaces


> On Tue, 2004-07-20 at 13:55, scohen wrote:
> > Also,
> >
> > You are using way to many quotes. Just write this:
> >
> > file_path="/some/where/Test Folder/"
> > echo $file_path
> > cd $file_path
> >
>
> Did you actually try this? Doesn't work in my shell. I'm sure he tried
> this first and only got more complicated when it failed to work.
>
> In your above example $file_path is an unquoted string that turns into
> two args, '/some/where/Test' and 'Folder/', when expanded and passed to
> cd.
>
> CD
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 21.07.2004 04:28:31 von Glynn Clements

Looking at this thread, quite a few people seem to have problems with
shell quoting.

As a general rule, literal values should be contained within single
quotes, i.e.:

file_path='/some/where/Test Folder/'

while variable references should almost always be contained within
double quotes:

cd "$file_path"

Within double quotes, variable expansions (e.g. $foo), command
substitutions (e.g. `foo` or $(foo)), arithmetic substitutions (e.g.
$[1+2] or $((1+2)) ) and similar (i.e. anything beginning with ` or $)
are still evaluated, and the backslash character can be used to quote
any of $ ` " \ or a newline.

Within single quotes, everything up to the next single quote is taken
literally (including the backslash character). If you need to include
a single quote, use '\'', e.g.:

$ echo 'it'\''s'
it's

[This parses as 'it' \' 's' (without the spaces), which the shell
interprets is it ' s (again, without the spaces).]

Unquoted variable expansions will subsequently be split into words so,
as has already been noted, the commands:

file_path='/some/where/Test Folder/'
cd $file_path

will result in the "cd" built-in command being called with two
arguments, namely:

/some/where/Test
and:
Folder/

For this reason, variable references should usually be enclosed in
double quotes; failure to do so is the main reason why scripts fail on
filenames (or other arguments) which contain spaces.

If you have trouble with shell syntax issues generally, it may help to
compile and install the following program:

#include

int main(int argc, char **argv)
{
int i;
for (i = 0; i < argc; i++)
printf("argv[%2d] = '%s'\n", i, argv[i]);
return 0;
}

You can then use it to see exactly what the shell is doing with your
command line before it gets to the program, e.g.:

$ file_path='/some/where/Test Folder/'
$ args $file_path
argv[ 0] = '/usr/local/bin/args'
argv[ 1] = '/some/where/Test'
argv[ 2] = 'Folder/'
$ args "$file_path"
argv[ 0] = '/usr/local/bin/args'
argv[ 1] = '/some/where/Test Folder/'

It may also help to read the bash(1) manpage. OK, so it's a bit more
than a "page" (I get 60 pages for 1.x, 86 pages for 2.x) but, if you
use the command line regularly, you could easily spend hundreds of
hours per year using bash.

--
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Stupid spaces

am 21.07.2004 09:11:19 von Calin Cosma

Again, thank you all for your fast support.



I solved the problem. I somehow missed the double quotes and left them
in the wrong place.

So now work like this:

file_path='/some/where/Test Folder/'
echo "$file_path"
cd "$file_path"




On Wed, 2004-07-21 at 05:28, Glynn Clements wrote:
> Looking at this thread, quite a few people seem to have problems with
> shell quoting.
>
> As a general rule, literal values should be contained within single
> quotes, i.e.:
>
> file_path='/some/where/Test Folder/'
>
> while variable references should almost always be contained within
> double quotes:
>
> cd "$file_path"
>
> Within double quotes, variable expansions (e.g. $foo), command
> substitutions (e.g. `foo` or $(foo)), arithmetic substitutions (e.g.
> $[1+2] or $((1+2)) ) and similar (i.e. anything beginning with ` or $)
> are still evaluated, and the backslash character can be used to quote
> any of $ ` " \ or a newline.
>
> Within single quotes, everything up to the next single quote is taken
> literally (including the backslash character). If you need to include
> a single quote, use '\'', e.g.:
>
> $ echo 'it'\''s'
> it's
>
> [This parses as 'it' \' 's' (without the spaces), which the shell
> interprets is it ' s (again, without the spaces).]
>
> Unquoted variable expansions will subsequently be split into words so,
> as has already been noted, the commands:
>
> file_path='/some/where/Test Folder/'
> cd $file_path
>
> will result in the "cd" built-in command being called with two
> arguments, namely:
>
> /some/where/Test
> and:
> Folder/
>
> For this reason, variable references should usually be enclosed in
> double quotes; failure to do so is the main reason why scripts fail on
> filenames (or other arguments) which contain spaces.
>
> If you have trouble with shell syntax issues generally, it may help to
> compile and install the following program:
>
> #include
>
> int main(int argc, char **argv)
> {
> int i;
> for (i = 0; i < argc; i++)
> printf("argv[%2d] = '%s'\n", i, argv[i]);
> return 0;
> }
>
> You can then use it to see exactly what the shell is doing with your
> command line before it gets to the program, e.g.:
>
> $ file_path='/some/where/Test Folder/'
> $ args $file_path
> argv[ 0] = '/usr/local/bin/args'
> argv[ 1] = '/some/where/Test'
> argv[ 2] = 'Folder/'
> $ args "$file_path"
> argv[ 0] = '/usr/local/bin/args'
> argv[ 1] = '/some/where/Test Folder/'
>
> It may also help to read the bash(1) manpage. OK, so it's a bit more
> than a "page" (I get 60 pages for 1.x, 86 pages for 2.x) but, if you
> use the command line regularly, you could easily spend hundreds of
> hours per year using bash.



------------------------------------------------------------ ---
Incearca acum noul sistem de dating oferit de portalul acasa.ro

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html