bash Script Using Filenames with Embedded Spaces

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

bash Script Using Filenames with Embedded Spaces

susemisc
I am trying to write a simple bash script to handle files with embedded
spaces in the filename.  For example, a listing of a directory using "ls -1"
gives:

        ls -l *.mp3
        -rw-r--r--  1 lucky users 20168832 2006-11-03 17:54 01 Allegro.mp3
        -rw-r--r--  1 lucky users  8105984 2006-11-03 17:53 02 Adagio un poco mosso.mp3
        -rw-r--r--  1 lucky users 10661760 2006-11-03 17:53 03 Rondo - Allegro.mp3

The following simplified script

        for i in `ls -1 *.mp3`
            do
                echo $i
            done

produces the following output:

        01
        Allegro.mp3
        02
        Adagio
        un
        poco
        mosso.mp3
        03
        Rondo
        -
        Allegro.mp3

I have tried various combinations of single and double quotes to no avail
including redirecting the "ls -1" listing to a file and escaping the
spaces with a backslash, again to no avail.

Surely there must be some trick I can use to handle this anomoly.?

Thank you,
Lucky Leavell

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Bugzilla from rll@felton.felton.ca.us
Lucky Leavell wrote:

> I am trying to write a simple bash script to handle files with embedded
> spaces in the filename.  For example, a listing of a directory using "ls -1"
> gives:
>
> ls -l *.mp3
> -rw-r--r--  1 lucky users 20168832 2006-11-03 17:54 01 Allegro.mp3
> -rw-r--r--  1 lucky users  8105984 2006-11-03 17:53 02 Adagio un poco mosso.mp3
> -rw-r--r--  1 lucky users 10661760 2006-11-03 17:53 03 Rondo - Allegro.mp3
>
> The following simplified script
>
> for i in `ls -1 *.mp3`
>    do
>        echo $i
>    done
>
> produces the following output:
>
> 01
> Allegro.mp3
> 02
> Adagio
> un
> poco
> mosso.mp3
> 03
> Rondo
> -
> Allegro.mp3
>
> I have tried various combinations of single and double quotes to no avail
> including redirecting the "ls -1" listing to a file and escaping the
> spaces with a backslash, again to no avail.
>
> Surely there must be some trick I can use to handle this anomoly.?
>
> Thank you,
> Lucky Leavell
>  

Start off your script with
IFS=""

and you will probably  be successul.  At least I was when I just
tried it a moment ago.

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Patrick Shanahan
In reply to this post by susemisc
* Lucky Leavell <[hidden email]> [11-06-06 17:27]:
> The following simplified script
>
> for i in `ls -1 *.mp3`
>    do
>        echo $i
>    done

perhaps use 'tr' to translate the 'space' to 'underline' or some other
normally unused char in the 'ls ...' and back in the 'echo $i...' ???
--
Patrick Shanahan                        Registered Linux User #207535
http://wahoo.no-ip.org                        @ http://counter.li.org
HOG # US1244711         Photo Album:  http://wahoo.no-ip.org/gallery2

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Jim Cunning
In reply to this post by susemisc
On Monday 06 November 2006 14:26, Lucky Leavell wrote:

> I am trying to write a simple bash script to handle files with embedded
> spaces in the filename.  For example, a listing of a directory using "ls
> -1" gives:
>
> ls -l *.mp3
> -rw-r--r--  1 lucky users 20168832 2006-11-03 17:54 01 Allegro.mp3
> -rw-r--r--  1 lucky users  8105984 2006-11-03 17:53 02 Adagio un poco
> mosso.mp3 -rw-r--r--  1 lucky users 10661760 2006-11-03 17:53 03 Rondo -
> Allegro.mp3
>
> The following simplified script
>
> for i in `ls -1 *.mp3`
>    do
>        echo $i
>    done

The 'for' command parses every token in each line returned by `ls -l *.mp3`.  
Instead try

        a_command_that_produces_output_lines_with_spaces  | while read one_line
    do
                        echo $one_line
                done

Note that the trivial example script above should produce identical output to
simply entering

        a_command_that_produces_output_lines_with_spaces

Jim

> Lucky Leavell

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Henne Vogelsang
In reply to this post by susemisc
Hi,

On Monday, November 06, 2006 at 17:26:47, Lucky Leavell wrote:

> The following simplified script
>
> for i in `ls -1 *.mp3`
>    do
>        echo $i
>    done

Useless use of ls.

for i in *.mp3; do echo $i; done

Henne

--
Henne Vogelsang,      http://hennevogel.de
"To die. In the rain. Alone."
                   Ernest Hemingway

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Wigbert Lindenbauer
In reply to this post by susemisc
Lucky Leavell wrote:

Hello Lucky,

do you tested the conmmand " basename " ?

basename --help or info basename  shows some help.

Best regards
Wigbert


> I am trying to write a simple bash script to handle files with embedded
> spaces in the filename.  For example, a listing of a directory using "ls -1"
> gives:
>
> ls -l *.mp3
> -rw-r--r--  1 lucky users 20168832 2006-11-03 17:54 01 Allegro.mp3
> -rw-r--r--  1 lucky users  8105984 2006-11-03 17:53 02 Adagio un poco mosso.mp3
> -rw-r--r--  1 lucky users 10661760 2006-11-03 17:53 03 Rondo - Allegro.mp3
>
> The following simplified script
>
> for i in `ls -1 *.mp3`
>    do
>        echo $i
>    done
>
> produces the following output:
>
> 01
> Allegro.mp3
> 02
> Adagio
> un
> poco
> mosso.mp3
> 03
> Rondo
> -
> Allegro.mp3
>
> I have tried various combinations of single and double quotes to no avail
> including redirecting the "ls -1" listing to a file and escaping the
> spaces with a backslash, again to no avail.
>
> Surely there must be some trick I can use to handle this anomoly.?
>
> Thank you,
> Lucky Leavell
>


--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

gregfreemyer
In reply to this post by susemisc
On 11/6/06, Lucky Leavell <[hidden email]> wrote:

> I am trying to write a simple bash script to handle files with embedded
> spaces in the filename.  For example, a listing of a directory using "ls -1"
> gives:
>
>         ls -l *.mp3
>         -rw-r--r--  1 lucky users 20168832 2006-11-03 17:54 01 Allegro.mp3
>         -rw-r--r--  1 lucky users  8105984 2006-11-03 17:53 02 Adagio un poco mosso.mp3
>         -rw-r--r--  1 lucky users 10661760 2006-11-03 17:53 03 Rondo - Allegro.mp3
>
> The following simplified script
>
>         for i in `ls -1 *.mp3`
>             do
>                 echo $i
>             done
>
> produces the following output:
>
>         01
>         Allegro.mp3
>         02
>         Adagio
>         un
>         poco
>         mosso.mp3
>         03
>         Rondo
>         -
>         Allegro.mp3
>
> I have tried various combinations of single and double quotes to no avail
> including redirecting the "ls -1" listing to a file and escaping the
> spaces with a backslash, again to no avail.
>
> Surely there must be some trick I can use to handle this anomoly.?
>
> Thank you,
> Lucky Leavell

In addition to the other responses, don't forget that find and xargs
both have specific options for supporting filenames with spaces in
them.

Greg
--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Geir A. Myrestrand
In reply to this post by susemisc
Lucky Leavell wrote:

> I am trying to write a simple bash script to handle files with embedded
> spaces in the filename.  For example, a listing of a directory using "ls -1"
> gives:
>
> ls -l *.mp3
> -rw-r--r--  1 lucky users 20168832 2006-11-03 17:54 01 Allegro.mp3
> -rw-r--r--  1 lucky users  8105984 2006-11-03 17:53 02 Adagio un poco mosso.mp3
> -rw-r--r--  1 lucky users 10661760 2006-11-03 17:53 03 Rondo - Allegro.mp3
>
> The following simplified script
>
> for i in `ls -1 *.mp3`
>    do
>        echo $i
>    done
>
> produces the following output:
>
> 01
> Allegro.mp3
> 02
> Adagio
> un
> poco
> mosso.mp3
> 03
> Rondo
> -
> Allegro.mp3
>
> I have tried various combinations of single and double quotes to no avail
> including redirecting the "ls -1" listing to a file and escaping the
> spaces with a backslash, again to no avail.
>
> Surely there must be some trick I can use to handle this anomoly.?
>
> Thank you,
> Lucky Leavell
>

for FILE in '*.mp3'; do echo ${FILE}; done

--

Geir A. Myrestrand

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

susemisc
In reply to this post by Henne Vogelsang
On Mon, 6 Nov 2006, Henne Vogelsang wrote:

> Hi,
>
> On Monday, November 06, 2006 at 17:26:47, Lucky Leavell wrote:
>
> > The following simplified script
> >
> > for i in `ls -1 *.mp3`
> >    do
> >        echo $i
> >    done
>
> Useless use of ls.
>
> for i in *.mp3; do echo $i; done
>
Thanks to all who replied; this suggestion works quite well as does Robert
Lewis'.  

Thank you,
Lucky

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Randall Schulz
In reply to this post by Geir A. Myrestrand
Geir,

On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
> ...
>
> for FILE in '*.mp3'; do echo ${FILE}; done

You should try these things before submitting them. That will only echo
(literally) *.mp3. Witness:

% for FILE in '*.mp3'; do echo ${FILE}; done
*.mp3


Randall Schulz


--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Geir A. Myrestrand
Randall R Schulz wrote:

> Geir,
>
> On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
>> ...
>>
>> for FILE in '*.mp3'; do echo ${FILE}; done
>
> You should try these things before submitting them. That will only echo
> (literally) *.mp3. Witness:
>
> % for FILE in '*.mp3'; do echo ${FILE}; done
> *.mp3
>
>
> Randall Schulz

I did:

chiangmai:/x # env | grep SHELL
SHELL=/bin/bash
chiangmai:/x # touch "01 Allegro.mp3"
chiangmai:/x # touch "02 Adagio un poco mosso.mp3"
chiangmai:/x # touch "03 Rondo - Allegro.mp3"
chiangmai:/x # ls -l
total 0
-rw-r--r-- 1 root root 0 Nov  6 21:55 01 Allegro.mp3
-rw-r--r-- 1 root root 0 Nov  6 21:55 02 Adagio un poco mosso.mp3
-rw-r--r-- 1 root root 0 Nov  6 21:56 03 Rondo - Allegro.mp3
chiangmai:/x # for FILE in '*.mp3'; do echo ${FILE}; done
01 Allegro.mp3 02 Adagio un poco mosso.mp3 03 Rondo - Allegro.mp3
chiangmai:/x # cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10

However, Randall is right --on the second run it doesn't give the right
output, so using for example find is the right solution here.

--

Geir A. Myrestrand

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Randall Schulz
On Monday 06 November 2006 19:03, Geir A. Myrestrand wrote:

> Randall R Schulz wrote:
> > Geir,
> >
> > On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
> >> ...
> >>
> >> for FILE in '*.mp3'; do echo ${FILE}; done
> >
> > You should try these things before submitting them. That will only
> > echo (literally) *.mp3. Witness:
> >
> > % for FILE in '*.mp3'; do echo ${FILE}; done
> > *.mp3
> >
> >
> > Randall Schulz
>
> I did:
>
> chiangmai:/x # env | grep SHELL
> SHELL=/bin/bash
> chiangmai:/x # touch "01 Allegro.mp3"
> chiangmai:/x # touch "02 Adagio un poco mosso.mp3"
> chiangmai:/x # touch "03 Rondo - Allegro.mp3"
> chiangmai:/x # ls -l
> total 0
> -rw-r--r-- 1 root root 0 Nov  6 21:55 01 Allegro.mp3
> -rw-r--r-- 1 root root 0 Nov  6 21:55 02 Adagio un poco mosso.mp3
> -rw-r--r-- 1 root root 0 Nov  6 21:56 03 Rondo - Allegro.mp3
> chiangmai:/x # for FILE in '*.mp3'; do echo ${FILE}; done
> 01 Allegro.mp3 02 Adagio un poco mosso.mp3 03 Rondo - Allegro.mp3

Here's what's happening. You set FILE to (again, literally) *.mp3. There
was one iteration of the loop (as evidenced by the fact that all the
output was on one line) and since ${FILE} was not quoted, the *.mp3 was
expanded as part of executing the echo command.

The result I showed occurred because there were no .mp3 files in the
directory where I executed it and I have the "nullglob" shell option
(see the shopt command: "help shopt" or "man bash") _unset_. With this
option off a glob (e.g., *.mp3) that matches no files is simply passed
through to the command unchanged. If I enable nullglob, then the "echo
*.mp3" produces no output (other than the newline always generated by
echo).


In any event, this is not a solution to the original problem of working
with file names with spaces embedded.

This approach works:

% touch "foo bar" "bar foo" "what not"

% for spaceFile in *\ *; do echo "[[$spaceFile]]"; done
[[bar foo]]
[[foo bar]]
[[what not]]


The *\ * in the for loop is just to exclude all the other files in the
directory that did _not_ have spaces in their names.


> ...
>
> --
>
> Geir A. Myrestrand


Randall Schulz

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Darryl Gregorash
In reply to this post by Geir A. Myrestrand
On 2006-11-06 21:03, Geir A. Myrestrand wrote:

> Randall R Schulz wrote:
>> Geir,
>>
>> On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
>>> ...
>>>
>>> for FILE in '*.mp3'; do echo ${FILE}; done
>>
>> You should try these things before submitting them. That will only
>> echo (literally) *.mp3. Witness:
>>
>> <snip>
>
>
> However, Randall is right --on the second run it doesn't give the
> right output, so using for example find is the right solution here.
>
No, all you need to do is get rid of the quotes around *.mp3.

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Geir A. Myrestrand
In reply to this post by Randall Schulz
Randall R Schulz wrote:

> On Monday 06 November 2006 19:03, Geir A. Myrestrand wrote:
>> Randall R Schulz wrote:
>>> Geir,
>>>
>>> On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
>>>> ...
>>>>
>>>> for FILE in '*.mp3'; do echo ${FILE}; done
>>> You should try these things before submitting them. That will only
>>> echo (literally) *.mp3. Witness:
>>>
>>> % for FILE in '*.mp3'; do echo ${FILE}; done
>>> *.mp3
>>>
>>>
>>> Randall Schulz
>> I did:
>>
>> chiangmai:/x # env | grep SHELL
>> SHELL=/bin/bash
>> chiangmai:/x # touch "01 Allegro.mp3"
>> chiangmai:/x # touch "02 Adagio un poco mosso.mp3"
>> chiangmai:/x # touch "03 Rondo - Allegro.mp3"
>> chiangmai:/x # ls -l
>> total 0
>> -rw-r--r-- 1 root root 0 Nov  6 21:55 01 Allegro.mp3
>> -rw-r--r-- 1 root root 0 Nov  6 21:55 02 Adagio un poco mosso.mp3
>> -rw-r--r-- 1 root root 0 Nov  6 21:56 03 Rondo - Allegro.mp3
>> chiangmai:/x # for FILE in '*.mp3'; do echo ${FILE}; done
>> 01 Allegro.mp3 02 Adagio un poco mosso.mp3 03 Rondo - Allegro.mp3
>
> Here's what's happening. You set FILE to (again, literally) *.mp3. There
> was one iteration of the loop (as evidenced by the fact that all the
> output was on one line) and since ${FILE} was not quoted, the *.mp3 was
> expanded as part of executing the echo command.
>
> The result I showed occurred because there were no .mp3 files in the
> directory where I executed it and I have the "nullglob" shell option
> (see the shopt command: "help shopt" or "man bash") _unset_. With this
> option off a glob (e.g., *.mp3) that matches no files is simply passed
> through to the command unchanged. If I enable nullglob, then the "echo
> *.mp3" produces no output (other than the newline always generated by
> echo).
>
>
> In any event, this is not a solution to the original problem of working
> with file names with spaces embedded.
>
> This approach works:
>
> % touch "foo bar" "bar foo" "what not"
>
> % for spaceFile in *\ *; do echo "[[$spaceFile]]"; done
> [[bar foo]]
> [[foo bar]]
> [[what not]]
>
>
> The *\ * in the for loop is just to exclude all the other files in the
> directory that did _not_ have spaces in their names.
>
>
>> ...
>>
>> --
>>
>> Geir A. Myrestrand
>
>
> Randall Schulz
>

Thanks for the detailed explanation. Shell expansion is not one of my
specialities. I usually use find myself when dealing with these type of
issues. Two variations with find are:

find . -name '*.mp3' -exec echo {} \;
find . -name '*.mp3' -exec ls -l {} \;

When I first used the for loop I only had one file in the directory, so
I did not even notice that it would expand into just one line.


--

Geir A. Myrestrand

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Geir A. Myrestrand
In reply to this post by Darryl Gregorash
Darryl Gregorash wrote:

> On 2006-11-06 21:03, Geir A. Myrestrand wrote:
>> Randall R Schulz wrote:
>>> Geir,
>>>
>>> On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
>>>> ...
>>>>
>>>> for FILE in '*.mp3'; do echo ${FILE}; done
>>> You should try these things before submitting them. That will only
>>> echo (literally) *.mp3. Witness:
>>>
>>> <snip>
>>
>> However, Randall is right --on the second run it doesn't give the
>> right output, so using for example find is the right solution here.
>>
> No, all you need to do is get rid of the quotes around *.mp3.
>
Yes, that works:

# for FILE in *.mp3; do echo ${FILE}; done
01 Allegro.mp3
02 Adagio un poco mosso.mp3
03 Rondo - Allegro.mp3


--

Geir A. Myrestrand


--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Randall Schulz
In reply to this post by Darryl Gregorash
On Monday 06 November 2006 19:19, Darryl Gregorash wrote:

> On 2006-11-06 21:03, Geir A. Myrestrand wrote:
> > Randall R Schulz wrote:
> >> Geir,
> >>
> >> On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
> >>> ...
> >>>
> >>> for FILE in '*.mp3'; do echo ${FILE}; done
> >>
> >> You should try these things before submitting them. That will only
> >> echo (literally) *.mp3. Witness:
> >>
> >> <snip>
> >
> > However, Randall is right --on the second run it doesn't give the
> > right output, so using for example find is the right solution here.
>
> No, all you need to do is get rid of the quotes around *.mp3.

No. The original question regards files whose names have spaces in them.
If you do that, you'll get the undesirable malfunctions shown in the
original posting.


Randall Schulz

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Geir A. Myrestrand
Randall R Schulz wrote:

> On Monday 06 November 2006 19:19, Darryl Gregorash wrote:
>> On 2006-11-06 21:03, Geir A. Myrestrand wrote:
>>> Randall R Schulz wrote:
>>>> Geir,
>>>>
>>>> On Monday 06 November 2006 15:40, Geir A. Myrestrand wrote:
>>>>> ...
>>>>>
>>>>> for FILE in '*.mp3'; do echo ${FILE}; done
>>>> You should try these things before submitting them. That will only
>>>> echo (literally) *.mp3. Witness:
>>>>
>>>> <snip>
>>> However, Randall is right --on the second run it doesn't give the
>>> right output, so using for example find is the right solution here.
>> No, all you need to do is get rid of the quotes around *.mp3.
>
> No. The original question regards files whose names have spaces in them.
> If you do that, you'll get the undesirable malfunctions shown in the
> original posting.
>
>
> Randall Schulz
>

It works fine for me:

# for FILE in *.mp3; do echo ${FILE}; done
01 Allegro.mp3
02 Adagio un poco mosso.mp3
03 Rondo - Allegro.mp3



--

Geir A. Myrestrand

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Darryl Gregorash
In reply to this post by Randall Schulz
On 2006-11-06 21:50, Randall R Schulz wrote:
>On Monday 06 November 2006 19:19, Darryl Gregorash wrote:
>  
>>No, all you need to do is get rid of the quotes around *.mp3.
>>    
>
>No. The original question regards files whose names have spaces in them.
>If you do that, you'll get the undesirable malfunctions shown in the
>original posting.
>  
Mileage must vary, then:

raven@static24-89-67-198:~> ./thingy
Antonio Vivaldi-Gloria Dixit Dominus Magnificat Choir of Kings College
Cambridge and the Academy of Ancient Music.m3u
Georg Friederich Händel-Water Music Suite.m3u
Johannes Brahms-Symphony no 1 in C minor Op 68 Thomas Sanderling
Philharmonia Orchestra.m3u
Johannes Brahms-Symphony no 2 in D major Op 73 Thomas Sanderling
Philharmonic Orchestra.m3u
Johannes Brahms-Symphony no 3 in F major Op 90 Tragic Overture Op 81
Thomas Sanderling Philharmonia Orchestra.m3u
Johannes Brahms-Symphony no 4 in E minor Op 98 Thomas Sanderling
Philharmonia Orchestra.m3u
Mikhail IppolitovIvanov-Liturgy of St John Chrysostom Op 37 Vespers Op
43.m3u
St Petersburg Chamber Choir-Russian Easter.m3u
The Mamas The Papas-Beautiful Thing.m3u
The Mamas The Papas-California Dreamin.m3u
The Mamas The Papas-If You Can Believe Your Eyes and Ears.m3u
The Tallis Scholars-Allegri Miserere Palestrina Missa Papae Marcelli
Mundy Vox Patris Caelestis.m3u
Virtuosi di Praga-Music for the Kings of Spain.m3u
Westminster Abbey Choir and the Abbey Consort-Miserere.m3u
Wolfgang Amadeus Mozart-Requiem Slovak Philharmonic Orchestra.m3u

raven@static24-89-67-198:~> cat thingy
cd /pub/music/mp3
for i in *.m3u; do echo $i; done
cd ~



--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Randall Schulz
On Monday 06 November 2006 20:04, Darryl Gregorash wrote:
> On 2006-11-06 21:50, Randall R Schulz wrote:
> >On Monday 06 November 2006 19:19, Darryl Gregorash wrote:
> >>No, all you need to do is get rid of the quotes around *.mp3.
> >
> >No. The original question regards files whose names have spaces in
> > them. If you do that, you'll get the undesirable malfunctions shown
> > in the original posting.
>
> Mileage must vary, then:

Not really.


> ...
>
> raven@static24-89-67-198:~> cat thingy
> cd /pub/music/mp3
> for i in *.m3u; do echo $i; done
> cd ~

Do something other than echo in the loopl. Try applying sum, or ls, e.g.
You'll find unless you quote $i it won't work.

Randall Schulz

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: bash Script Using Filenames with Embedded Spaces

Geir A. Myrestrand
Randall R Schulz wrote:

> On Monday 06 November 2006 20:04, Darryl Gregorash wrote:
>> On 2006-11-06 21:50, Randall R Schulz wrote:
>>> On Monday 06 November 2006 19:19, Darryl Gregorash wrote:
>>>> No, all you need to do is get rid of the quotes around *.mp3.
>>> No. The original question regards files whose names have spaces in
>>> them. If you do that, you'll get the undesirable malfunctions shown
>>> in the original posting.
>> Mileage must vary, then:
>
> Not really.
>
>
>> ...
>>
>> raven@static24-89-67-198:~> cat thingy
>> cd /pub/music/mp3
>> for i in *.m3u; do echo $i; done
>> cd ~
>
> Do something other than echo in the loopl. Try applying sum, or ls, e.g.
> You'll find unless you quote $i it won't work.
>
> Randall Schulz
>

Randall is right, you need to quote the variable if you use it as an
argument to a program that expects one token.

An example is if you want to copy the MP3 files, the first argument to
cp must be the full filename, not just the first token of the filename...

However, as long as echo is sufficient then it will work as pointed out
by Randall.

--

Geir A. Myrestrand

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


12