suicidaleggroll |
03-02-2012 09:42 AM |
Quote:
Originally Posted by sag47
(Post 4616838)
No it won't. Do an example yourself and see.
Code:
touch old\ file.old
touch old-file.old
for i in *.old; do mv "$i" "${i/.old/.new}"; done
You will get "old not found" and "file.old not found" errors when you run that for loop. Unless you've changed your field separator in the IFS variable to see newlines as the field separator that for loop does not work on file names with spaces. The for loop separates arguments based on spaces. That's why I gave you the while read line loop.
|
RHEL:
Code:
[eggroll@picard test]$ touch old\ file.old
[eggroll@picard test]$ touch old-file.old
[eggroll@picard test]$ for i in *.old; do mv "$i" "${i/.old/.new}"; done
[eggroll@picard test]$ ls
old file.new old-file.new
I have also tested it successfully on CentOS, Fedora, Mint, OpenSUSE, Cygwin, and BusyBox. None of them have modified IFS. I just set up the Mint box not 24 hours ago, haven't modified anything on it really, and it works fine. If I had access to more distros, I would try them as well, but so far I haven't found a single distro that it doesn't work on, including the limited ones used on embedded systems like the GESBC-9260S and Gumstix.
You would be right if I had written it like:
Code:
for i in $(ls *.old); do mv "$i" "${i/.old/.new}"; done
but that's why I didn't write it like that. "for i in *.old" does not work the same way as "for i in $(ls *.old)", and does not suffer from the problem you're describing, at least not on any system I've ever used.
|