Subject: Re: for command doesn't handle spaces in filename well! - msg#00063
List: shells.bash.bugs
"Alex" <aolson1@xxxxxxx> wrote:
>
echo HELLO>"HELLO THERE"
>
echo HI >"HI THERE"
>
for f in H*; do echo $f;done
>
>
Resulting Output:
>
HELLO THERE
>
HI THERE
This is the correct behavior, and it has nothing to do with "for". It
has to do with unquoted variable expansion. If you want to preserve
the spaces, use "$f" instead of $f.
paul
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
for command doesn't handle spaces in filename well!
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc'
-DSHELL -DHAVE_CONFIG_H -D_GNU_SOURCE -I. -I. -I./include -I./lib -O2
-march=i386
-mcpu=i686
uname output: Linux Bhodoo.HomeLinux.Net 2.4.18-18.7.x #1 Wed Nov 13
19:05:27 EST
2002 i686 unknown
Machine Type: i686-pc-linux-gnu
Bash Version: 2.05a
Patch Level: 0
Release Status: release
Description:
I was using the 'for' command under bash in a script. It was
operating on an entire
directory of files, like
for f in *; do .......; done
I discovered that on filenames with two consequtive spaces in
them, that the for
command somehow 'removes' all but one space.
Repeat-By:
Try the following code:
echo HELLO>"HELLO THERE"
echo HI >"HI THERE"
for f in H*; do echo $f;done
Resulting Output:
HELLO THERE
HI THERE
Next Message by Date:
click to view message preview
未承諾広告※電子メール広告
<???M?Ò>
?d?q???[???L???Ð
?¡?ã?A?L???ð?²?ó?]?µ?È?¢?û?Í?±?±?Ö
(?K?¸?{?¶?É? ?È?½?Ì???[???A?h???X?Ì?Ý?ð?¨???«?º?³?¢?j
me463886@xxxxxxxxxxxxxxxxxxxx
???[???A?h???X?ð?²?L?ü?µ?Ä??¾?³?¢?B
?§104-0061
?????s?????æ?â?À8-19-3
?æ2?E?C???O?r???@3F
???[???}?K?W????s
TEL?@03-3544-6222
FAX?@03-3544-6218
===============================================================
?â?è?¤?i?Î?©?è?W?ß?Ü?µ?½?Ì?Å?A?Á?³?ê?é?°?ê?ª? ?è?Ü?·?Ì?Å
?¨?\???Ý?Í?¨???ß?É?I
=================================================================
???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\??
? ?r?f?I?Ì???E?????r?f?I?E?Á?ê?_?b?`???C?t?E?r?l?N???u
?@?@ ?`?u?j?D?å?W?E?????ð?Û?E?r?d?w?t?????h?E?A?_???g?O?b?Y?È?Ç
???@?A?_???g?Ö?A?Ì?î?ñ???Ú?@??
??????????????????????????????????????
?@?@?¨?\???Ý?E?²???¶?E?¤?i?Ú?×???Í?@
?@?@?@?@?@?º?L?t?q?k?ð?N???b?N?µ?Ä?²???º?³?¢?B
??????????????????????????????????????
?«?@?@?@?@?«?@?@?@?@?«?@
?@?@?@http://changeboy.kir.jp/
???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\??
?@?@?@?@?@?@?@?@?J?^?O?b?Y?E?É?é?î?ñ??
?@?@?@?@?h?Æ?O?b?Y?E?à?×?¯?î?ñ?E?_?C?G?b?g?H?i?È?Ç?@
?@?@?@?@?@?@?@?@???@?»?Ì?¼?î?ñ???Ú?@??
??????????????????????????????????????
?@?@?¨?\???Ý?E?²???¶?E?¤?i?Ú?×???Í?@
?@?@?@?@?@?º?L?t?q?k?ð?N???b?N?µ?Ä?²???º?³?¢?B
??????????????????????????????????????
?«?@?@?@?@?«?@?@?@?@?«?@
http://changeboy.kir.jp/index2.html
???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\??
Previous Message by Thread:
click to view message preview
for command doesn't handle spaces in filename well!
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc'
-DSHELL -DHAVE_CONFIG_H -D_GNU_SOURCE -I. -I. -I./include -I./lib -O2
-march=i386
-mcpu=i686
uname output: Linux Bhodoo.HomeLinux.Net 2.4.18-18.7.x #1 Wed Nov 13
19:05:27 EST
2002 i686 unknown
Machine Type: i686-pc-linux-gnu
Bash Version: 2.05a
Patch Level: 0
Release Status: release
Description:
I was using the 'for' command under bash in a script. It was
operating on an entire
directory of files, like
for f in *; do .......; done
I discovered that on filenames with two consequtive spaces in
them, that the for
command somehow 'removes' all but one space.
Repeat-By:
Try the following code:
echo HELLO>"HELLO THERE"
echo HI >"HI THERE"
for f in H*; do echo $f;done
Resulting Output:
HELLO THERE
HI THERE
Next Message by Thread:
click to view message preview
未承諾広告※電子メール広告
<???M?Ò>
?d?q???[???L???Ð
?¡?ã?A?L???ð?²?ó?]?µ?È?¢?û?Í?±?±?Ö
(?K?¸?{?¶?É? ?È?½?Ì???[???A?h???X?Ì?Ý?ð?¨???«?º?³?¢?j
me463886@xxxxxxxxxxxxxxxxxxxx
???[???A?h???X?ð?²?L?ü?µ?Ä??¾?³?¢?B
?§104-0061
?????s?????æ?â?À8-19-3
?æ2?E?C???O?r???@3F
???[???}?K?W????s
TEL?@03-3544-6222
FAX?@03-3544-6218
===============================================================
?â?è?¤?i?Î?©?è?W?ß?Ü?µ?½?Ì?Å?A?Á?³?ê?é?°?ê?ª? ?è?Ü?·?Ì?Å
?¨?\???Ý?Í?¨???ß?É?I
=================================================================
???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\??
? ?r?f?I?Ì???E?????r?f?I?E?Á?ê?_?b?`???C?t?E?r?l?N???u
?@?@ ?`?u?j?D?å?W?E?????ð?Û?E?r?d?w?t?????h?E?A?_???g?O?b?Y?È?Ç
???@?A?_???g?Ö?A?Ì?î?ñ???Ú?@??
??????????????????????????????????????
?@?@?¨?\???Ý?E?²???¶?E?¤?i?Ú?×???Í?@
?@?@?@?@?@?º?L?t?q?k?ð?N???b?N?µ?Ä?²???º?³?¢?B
??????????????????????????????????????
?«?@?@?@?@?«?@?@?@?@?«?@
?@?@?@http://changeboy.kir.jp/
???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\??
?@?@?@?@?@?@?@?@?J?^?O?b?Y?E?É?é?î?ñ??
?@?@?@?@?h?Æ?O?b?Y?E?à?×?¯?î?ñ?E?_?C?G?b?g?H?i?È?Ç?@
?@?@?@?@?@?@?@?@???@?»?Ì?¼?î?ñ???Ú?@??
??????????????????????????????????????
?@?@?¨?\???Ý?E?²???¶?E?¤?i?Ú?×???Í?@
?@?@?@?@?@?º?L?t?q?k?ð?N???b?N?µ?Ä?²???º?³?¢?B
??????????????????????????????????????
?«?@?@?@?@?«?@?@?@?@?«?@
http://changeboy.kir.jp/index2.html
???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\???\?\?\??