* Stupid spaces
@ 2004-02-12 21:08 Scott Taylor
2004-02-12 21:23 ` Alok K. Dhir
` (5 more replies)
0 siblings, 6 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-12 21:08 UTC (permalink / raw)
To: linux-admin
Hello all,
I've done this before, but so long ago I can't find it again. I have a
bunch of files with spaces in them and I want to rename them with the
spaces removed.
I have a rename command that came with RH7.2 but doesn't do the job
rename 's/\ //g' *
does nothing in bash
So I wrote a script many moons ago to do this but I can't remember which
server it was on, let alone how I did it. Something with tr and mv methinks.
anyone?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:08 Stupid spaces Scott Taylor
@ 2004-02-12 21:23 ` Alok K. Dhir
2004-02-12 22:19 ` Scott Taylor
2004-02-12 21:39 ` Yu Chen
` (4 subsequent siblings)
5 siblings, 1 reply; 26+ messages in thread
From: Alok K. Dhir @ 2004-02-12 21:23 UTC (permalink / raw)
To: Scott Taylor; +Cc: linux-admin
[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]
The attached rename.pl is invaluable for such tasks.
Use it exactly like your bash rename attempt. You can use pretty much
any perl in-place-modifier construct - s/X/Y/, tr/A-Z/a-z/
(upper->lower), etc.
Not sure where I found this originally, but it's extremely handy.
Al
Scott Taylor wrote:
> Hello all,
>
> I've done this before, but so long ago I can't find it again. I have
> a bunch of files with spaces in them and I want to rename them with
> the spaces removed.
>
> I have a rename command that came with RH7.2 but doesn't do the job
> rename 's/\ //g' *
> does nothing in bash
>
> So I wrote a script many moons ago to do this but I can't remember
> which server it was on, let alone how I did it. Something with tr and
> mv methinks.
>
> anyone?
>
> -
> 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
>
--
Alok K. Dhir <adhir@symplicity.com>
Symplicity Corporation
http://solutions.symplicity.com
703 351 6987 (w) | 703 351-6357 (f)
[-- Attachment #2: rename.pl --]
[-- Type: text/plain, Size: 226 bytes --]
#!/usr/bin/perl
if (@ARGV == 0) {
die "usage: rename PATTERN FILESPEC\n";
}
$pattern=shift;
foreach (@ARGV) {
my $oldname=$_;
my $newname=$_;
eval ("\$newname=~$pattern");
rename($oldname, $newname);
}
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:08 Stupid spaces Scott Taylor
2004-02-12 21:23 ` Alok K. Dhir
@ 2004-02-12 21:39 ` Yu Chen
2004-02-12 22:18 ` Scott Taylor
2004-02-13 2:15 ` rich+ml
` (3 subsequent siblings)
5 siblings, 1 reply; 26+ messages in thread
From: Yu Chen @ 2004-02-12 21:39 UTC (permalink / raw)
To: Scott Taylor; +Cc: linux-admin
On RH, it does have a command 'rename', but not the way you used it.
Just type
rename ' ' '' *
couple of times to get rid of all the spaces
Chen
On Thu, 12 Feb 2004, Scott Taylor wrote:
> Hello all,
>
> I've done this before, but so long ago I can't find it again. I have a
> bunch of files with spaces in them and I want to rename them with the
> spaces removed.
>
> I have a rename command that came with RH7.2 but doesn't do the job
> rename 's/\ //g' *
> does nothing in bash
>
> So I wrote a script many moons ago to do this but I can't remember which
> server it was on, let alone how I did it. Something with tr and mv methinks.
>
> anyone?
>
> -
> 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
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:39 ` Yu Chen
@ 2004-02-12 22:18 ` Scott Taylor
0 siblings, 0 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-12 22:18 UTC (permalink / raw)
To: Yu Chen; +Cc: linux-admin
At 01:39 PM 02/12/2004, Yu Chen wrote:
>On RH, it does have a command 'rename', but not the way you used it.
>Just type
>rename ' ' '' *
>couple of times to get rid of all the spaces
Oh! Hehe, looks like a DOS command. LOL
Cheers.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:23 ` Alok K. Dhir
@ 2004-02-12 22:19 ` Scott Taylor
0 siblings, 0 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-12 22:19 UTC (permalink / raw)
To: linux-admin
At 01:23 PM 02/12/2004, Alok K. Dhir wrote:
>The attached rename.pl is invaluable for such tasks.
>
>Use it exactly like your bash rename attempt. You can use pretty much any
>perl in-place-modifier construct - s/X/Y/, tr/A-Z/a-z/ (upper->lower), etc.
>
>Not sure where I found this originally, but it's extremely handy.
>
>
>#!/usr/bin/perl
>
>if (@ARGV == 0) {
> die "usage: rename PATTERN FILESPEC\n";
>}
>
>$pattern=shift;
>
>foreach (@ARGV) {
> my $oldname=$_;
> my $newname=$_;
> eval ("\$newname=~$pattern");
> rename($oldname, $newname);
>}
Very. Thanks. Not a BASH script, but works great.
Thanks.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:08 Stupid spaces Scott Taylor
2004-02-12 21:23 ` Alok K. Dhir
2004-02-12 21:39 ` Yu Chen
@ 2004-02-13 2:15 ` rich+ml
2004-02-13 4:07 ` Emiliano Castagnari
` (2 subsequent siblings)
5 siblings, 0 replies; 26+ messages in thread
From: rich+ml @ 2004-02-13 2:15 UTC (permalink / raw)
To: Scott Taylor; +Cc: linux-admin
How about:
for x in *; do mv $x ${x// /_}; done
On Thu, 12 Feb 2004, Scott Taylor wrote:
> Date: Thu, 12 Feb 2004 13:08:04 -0800
> From: Scott Taylor <scott@dctchambers.com>
> To: linux-admin@vger.kernel.org
> Subject: Stupid spaces
>
> Hello all,
>
> I've done this before, but so long ago I can't find it again. I have a
> bunch of files with spaces in them and I want to rename them with the
> spaces removed.
>
> I have a rename command that came with RH7.2 but doesn't do the job
> rename 's/\ //g' *
> does nothing in bash
>
> So I wrote a script many moons ago to do this but I can't remember which
> server it was on, let alone how I did it. Something with tr and mv methinks.
>
> anyone?
>
> -
> 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
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:08 Stupid spaces Scott Taylor
` (2 preceding siblings ...)
2004-02-13 2:15 ` rich+ml
@ 2004-02-13 4:07 ` Emiliano Castagnari
2004-02-13 16:56 ` Scott Taylor
2004-02-13 6:51 ` Agus Budy Wuysang
[not found] ` <Pine.LNX.4.44.0402121811240.3031-100000@deadrat.localdomai n>
5 siblings, 1 reply; 26+ messages in thread
From: Emiliano Castagnari @ 2004-02-13 4:07 UTC (permalink / raw)
To: linux-admin
El [ Thu 12, Feb 04 - 13:08 ] , Scott Taylor expreso:
> Hello all,
>
> I've done this before, but so long ago I can't find it again. I have a
> bunch of files with spaces in them and I want to rename them with the
> spaces removed.
>
> I have a rename command that came with RH7.2 but doesn't do the job
> rename 's/\ //g' *
> does nothing in bash
>
> So I wrote a script many moons ago to do this but I can't remember which
> server it was on, let alone how I did it. Something with tr and mv
> methinks.
>
> anyone?
Here you go, my simple aproach using the virtudes of bash scripting:
-- cut --
#!/bin/bash
DIR=$1
TOKEN="_"
cd $DIR;
# Here, we first wipe out spaces (actually, we replace them), otherwise
# a name like "my tex file.tex" would produce 3 elements, "my", "tex" and "file.tex"
for file in $(ls | sed -r 's/ /_:_/g'); do
new_name="$(echo $file | sed -r "s/_:_/$TOKEN/g")"
name="$(echo $file | sed -r 's/_:_/ /g')"
if [ -f "$name" ]; then
echo " Moving $name => $new_name"
mv "$name" "$new_name"
else
echo "$file does not exists (or element was not splited correctly in command: ls | tr ' ' ':' )"
fi
done
echo " done ..."
-- /cut --
Hope you find this usefull
"...
Master Foo once said to a visiting programmer:
There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.
..."
Rootles Root - Eric S. Raymond.
http://catb.org/~esr/writings/unix-koans/ten-thousand.html
--
Emiliano Castagnari
# Debian Sarge - GNU/Linux - Athos 2.6.2 #
# JID: pretorian@jabber.sk
# ICQ: 107462374 - Nick: mem
--------------------------------------------------
- } [ Libera tu mente - Libera tu Codigo ] { -
--------------------------------------------------
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-12 21:08 Stupid spaces Scott Taylor
` (3 preceding siblings ...)
2004-02-13 4:07 ` Emiliano Castagnari
@ 2004-02-13 6:51 ` Agus Budy Wuysang
2004-02-13 17:15 ` Scott Taylor
[not found] ` <Pine.LNX.4.44.0402121811240.3031-100000@deadrat.localdomai n>
5 siblings, 1 reply; 26+ messages in thread
From: Agus Budy Wuysang @ 2004-02-13 6:51 UTC (permalink / raw)
To: linux-admin; +Cc: Scott Taylor
Scott Taylor wrote:
> Hello all,
>
> I've done this before, but so long ago I can't find it again. I have a
> bunch of files with spaces in them and I want to rename them with the
> spaces removed.
>
> I have a rename command that came with RH7.2 but doesn't do the job
> rename 's/\ //g' *
> does nothing in bash
rename doesn't work like DOS' rename, but:
rename old_pattern new_pattern files...
> So I wrote a script many moons ago to do this but I can't remember which
> server it was on, let alone how I did it. Something with tr and mv
> methinks.
>
> anyone?
If you're lucky enough to have bash V2, use (faster):
for f in *;do mv -i "$f" "${f// /}";done
otherwise:
for f in *;do mv -i "$f" "$(echo $f|tr -d ' ')";done
If your actual intention of getting rid of spaces were
to get around difficulties in shell command globbing/parsing,
you should learn more about "find -print0" & "xargs -0" instead.
--
+-R-| Mozilla 1.6 Gecko20040116 |-H-| Powered by Linux 2.4.x |-9-+
|/v\ Agus Budy Wuysang MIS Department |
| | Phone: +62-21-344-1316 ext 317 GSM: +62-816-1972-051 |
+------------| http://www.fasw.co.id/person/supes/ |-------------+
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
[not found] ` <Pine.LNX.4.44.0402121811240.3031-100000@deadrat.localdomai n>
@ 2004-02-13 16:33 ` Scott Taylor
2004-02-13 17:26 ` rich+ml
[not found] ` <Pine.LNX.4.44.0402130907370.3031-100000@deadrat.localdomai n>
0 siblings, 2 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-13 16:33 UTC (permalink / raw)
To: linux-admin
At 06:15 PM 02/12/2004, rich+ml@lclogic.com wrote:
>How about:
>
> for x in *; do mv $x ${x// /_}; done
That's kinda what I was thinking, only problem with that is, the file named
"blah blah.p" will cause an error as bash/sh/ksh will think it is two files.
mv: cannot stat `blah': No such file or directory
mv: cannot stat `blah.p': No such file or directory
even tried using `ls -c1` same thing. Worse thing is I know I did this
before, so long ago, maybe I used Perl after all. Hmm...
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-13 4:07 ` Emiliano Castagnari
@ 2004-02-13 16:56 ` Scott Taylor
0 siblings, 0 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-13 16:56 UTC (permalink / raw)
To: linux-admin
At 08:07 PM 02/12/2004, Emiliano Castagnari wrote:
>El [ Thu 12, Feb 04 - 13:08 ] , Scott Taylor expreso:
> > Hello all,
> >
> > I've done this before, but so long ago I can't find it again. I have a
> > bunch of files with spaces in them and I want to rename them with the
> > spaces removed.
> >
> > I have a rename command that came with RH7.2 but doesn't do the job
> > rename 's/\ //g' *
> > does nothing in bash
> >
> > So I wrote a script many moons ago to do this but I can't remember which
> > server it was on, let alone how I did it. Something with tr and mv
> > methinks.
> >
> > anyone?
>
>Here you go, my simple aproach using the virtudes of bash scripting:
Interesting. Only it doesn't "remove" the spaces it simply replaces them
with something else.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-13 6:51 ` Agus Budy Wuysang
@ 2004-02-13 17:15 ` Scott Taylor
0 siblings, 0 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-13 17:15 UTC (permalink / raw)
To: linux-admin
At 10:51 PM 02/12/2004, Agus Budy Wuysang wrote:
>Scott Taylor wrote:
>
>If you're lucky enough to have bash V2, use (faster):
>
>for f in *;do mv -i "$f" "${f// /}";done
>
>otherwise:
>
>for f in *;do mv -i "$f" "$(echo $f|tr -d ' ')";done
This last works, it also works in more then just bash so I like it best. I
have more then one OS that store Windows files for users. :)
I don't remember using echo in it last time but, it works...
Cheers.
Scott.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-02-13 16:33 ` Scott Taylor
@ 2004-02-13 17:26 ` rich+ml
[not found] ` <Pine.LNX.4.44.0402130907370.3031-100000@deadrat.localdomai n>
1 sibling, 0 replies; 26+ messages in thread
From: rich+ml @ 2004-02-13 17:26 UTC (permalink / raw)
To: Scott Taylor; +Cc: linux-admin
Works for me, however I did forget to quote $x in original example.
[rich@deadrat ~/test]$ ls -l
total 0
-rw-rw-r-- 1 rich rich 0 Feb 13 09:19 blah blah.p
-rw-rw-r-- 1 rich rich 0 Feb 13 09:19 this is a test
[rich@deadrat ~/test]$ for x in *; do mv "$x" ${x// /_}; done
[rich@deadrat ~/test]$ ls -l
total 0
-rw-rw-r-- 1 rich rich 0 Feb 13 09:19 blah_blah.p
-rw-rw-r-- 1 rich rich 0 Feb 13 09:19 this_is_a_test
[rich@deadrat ~/test]$ bash --version
GNU bash, version 2.05.8(1)-release (i386-redhat-linux-gnu)
Copyright 2000 Free Software Foundation, Inc.
On Fri, 13 Feb 2004, Scott Taylor wrote:
> Date: Fri, 13 Feb 2004 08:33:33 -0800
> From: Scott Taylor <scott@dctchambers.com>
> To: linux-admin@vger.kernel.org
> Subject: Re: Stupid spaces
>
> At 06:15 PM 02/12/2004, rich+ml@lclogic.com wrote:
> >How about:
> >
> > for x in *; do mv $x ${x// /_}; done
>
> That's kinda what I was thinking, only problem with that is, the file named
> "blah blah.p" will cause an error as bash/sh/ksh will think it is two files.
> mv: cannot stat `blah': No such file or directory
> mv: cannot stat `blah.p': No such file or directory
>
> even tried using `ls -c1` same thing. Worse thing is I know I did this
> before, so long ago, maybe I used Perl after all. Hmm...
>
> -
> 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
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
[not found] ` <Pine.LNX.4.44.0402130907370.3031-100000@deadrat.localdomai n>
@ 2004-02-13 17:33 ` Scott Taylor
0 siblings, 0 replies; 26+ messages in thread
From: Scott Taylor @ 2004-02-13 17:33 UTC (permalink / raw)
To: linux-admin
At 09:26 AM 02/13/2004, rich+ml@lclogic.com wrote:
>Works for me, however I did forget to quote $x in original example.
That would do it.
for x in *; do mv "$x" ${x// /}; done
removes the spaces, but only works in bash 2. :(
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
@ 2004-02-13 19:13 urgrue
0 siblings, 0 replies; 26+ messages in thread
From: urgrue @ 2004-02-13 19:13 UTC (permalink / raw)
To: linux-admin
well since we're all sharing space-removal tactics, here's my version: a
script i made to remove space (and other chars i dont like) from all files
in the current dir:
ls -1A > /tmp/desp.tmp
while read line
do
new=`echo -n "$line" | tr [:space:] _ | tr -d
[=\(=][=\)=][=]=][=[=][=!=][=\'=][=,=][=?=] | tr [:upper:] [:lower:]`
if [ "$new" = "$line" ] ; then
continue
fi
mv -i -- "$line" "$new"
done < /tmp/desp.tmp
rm /tmp/desp.tmp
>>At 09:26 AM 02/13/2004, rich+ml@lclogic.com wrote:
>>>Works for me, however I did forget to quote $x in original example.
>>
>>That would do it.
>>for x in *; do mv "$x" ${x// /}; done
>>removes the spaces, but only works in bash 2. :(
>>
>>
>>-
>>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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Stupid spaces
@ 2004-07-19 13:29 calin
2004-07-19 13:56 ` Chris DiTrani
` (4 more replies)
0 siblings, 5 replies; 26+ messages in thread
From: calin @ 2004-07-19 13:29 UTC (permalink / raw)
To: linux-admin
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 13:29 calin
@ 2004-07-19 13:56 ` Chris DiTrani
2004-07-19 14:59 ` calin
2004-07-19 14:45 ` Scott Taylor
` (3 subsequent siblings)
4 siblings, 1 reply; 26+ messages in thread
From: Chris DiTrani @ 2004-07-19 13:56 UTC (permalink / raw)
To: calin; +Cc: linux-admin
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 13:29 calin
2004-07-19 13:56 ` Chris DiTrani
@ 2004-07-19 14:45 ` Scott Taylor
2004-07-19 14:52 ` Scott Taylor
2004-07-20 17:48 ` scohen
` (2 subsequent siblings)
4 siblings, 1 reply; 26+ messages in thread
From: Scott Taylor @ 2004-07-19 14:45 UTC (permalink / raw)
To: linux-admin
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.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 14:45 ` Scott Taylor
@ 2004-07-19 14:52 ` Scott Taylor
0 siblings, 0 replies; 26+ messages in thread
From: Scott Taylor @ 2004-07-19 14:52 UTC (permalink / raw)
To: linux-admin
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 13:56 ` Chris DiTrani
@ 2004-07-19 14:59 ` calin
0 siblings, 0 replies; 26+ messages in thread
From: calin @ 2004-07-19 14:59 UTC (permalink / raw)
To: Chris DiTrani; +Cc: linux-admin
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 13:29 calin
2004-07-19 13:56 ` Chris DiTrani
2004-07-19 14:45 ` Scott Taylor
@ 2004-07-20 17:48 ` scohen
2004-07-20 18:22 ` Adam Lang
2004-07-20 17:55 ` scohen
2004-07-21 2:28 ` Glynn Clements
4 siblings, 1 reply; 26+ messages in thread
From: scohen @ 2004-07-20 17:48 UTC (permalink / raw)
To: calin; +Cc: linux-admin
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
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 13:29 calin
` (2 preceding siblings ...)
2004-07-20 17:48 ` scohen
@ 2004-07-20 17:55 ` scohen
2004-07-20 18:20 ` Chris DiTrani
2004-07-21 2:28 ` Glynn Clements
4 siblings, 1 reply; 26+ messages in thread
From: scohen @ 2004-07-20 17:55 UTC (permalink / raw)
To: calin; +Cc: linux-admin
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
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-20 17:55 ` scohen
@ 2004-07-20 18:20 ` Chris DiTrani
2004-07-20 18:37 ` Adam Lang
0 siblings, 1 reply; 26+ messages in thread
From: Chris DiTrani @ 2004-07-20 18:20 UTC (permalink / raw)
To: scohen; +Cc: linux-admin
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-20 17:48 ` scohen
@ 2004-07-20 18:22 ` Adam Lang
0 siblings, 0 replies; 26+ messages in thread
From: Adam Lang @ 2004-07-20 18:22 UTC (permalink / raw)
Cc: linux-admin
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" <scohen@scohen.mysticjj.com>
To: "calin" <calin_cosma@mymail.ro>
Cc: <linux-admin@vger.kernel.org>
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-20 18:20 ` Chris DiTrani
@ 2004-07-20 18:37 ` Adam Lang
0 siblings, 0 replies; 26+ messages in thread
From: Adam Lang @ 2004-07-20 18:37 UTC (permalink / raw)
Cc: linux-admin
oooooh
The catch is the space ... didn't even notice
Need to retest :p
----- Original Message -----
From: "Chris DiTrani" <cditrani@livedata.com>
To: "scohen" <scohen@scohen.mysticjj.com>
Cc: <linux-admin@vger.kernel.org>
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-19 13:29 calin
` (3 preceding siblings ...)
2004-07-20 17:55 ` scohen
@ 2004-07-21 2:28 ` Glynn Clements
2004-07-21 7:11 ` calin
4 siblings, 1 reply; 26+ messages in thread
From: Glynn Clements @ 2004-07-21 2:28 UTC (permalink / raw)
To: linux-admin
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 <stdio.h>
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 <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Stupid spaces
2004-07-21 2:28 ` Glynn Clements
@ 2004-07-21 7:11 ` calin
0 siblings, 0 replies; 26+ messages in thread
From: calin @ 2004-07-21 7:11 UTC (permalink / raw)
To: linux-admin
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 <stdio.h>
>
> 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
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2004-07-21 7:11 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-12 21:08 Stupid spaces Scott Taylor
2004-02-12 21:23 ` Alok K. Dhir
2004-02-12 22:19 ` Scott Taylor
2004-02-12 21:39 ` Yu Chen
2004-02-12 22:18 ` Scott Taylor
2004-02-13 2:15 ` rich+ml
2004-02-13 4:07 ` Emiliano Castagnari
2004-02-13 16:56 ` Scott Taylor
2004-02-13 6:51 ` Agus Budy Wuysang
2004-02-13 17:15 ` Scott Taylor
[not found] ` <Pine.LNX.4.44.0402121811240.3031-100000@deadrat.localdomai n>
2004-02-13 16:33 ` Scott Taylor
2004-02-13 17:26 ` rich+ml
[not found] ` <Pine.LNX.4.44.0402130907370.3031-100000@deadrat.localdomai n>
2004-02-13 17:33 ` Scott Taylor
-- strict thread matches above, loose matches on Subject: below --
2004-02-13 19:13 urgrue
2004-07-19 13:29 calin
2004-07-19 13:56 ` Chris DiTrani
2004-07-19 14:59 ` calin
2004-07-19 14:45 ` Scott Taylor
2004-07-19 14:52 ` Scott Taylor
2004-07-20 17:48 ` scohen
2004-07-20 18:22 ` Adam Lang
2004-07-20 17:55 ` scohen
2004-07-20 18:20 ` Chris DiTrani
2004-07-20 18:37 ` Adam Lang
2004-07-21 2:28 ` Glynn Clements
2004-07-21 7:11 ` calin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).