[Gllug] one-liner

James Hawtin oolon at ankh.org
Tue Nov 15 10:56:01 UTC 2011


JLMS wrote:
>
> It would have been even more interesting to mention a possible
> solution taking care of the problem you correctly highlight:
>
> In bash:
>
> for i in "*.html" ; do sed -i -e 's/fish/chips/g' $i ; done
>
>
>   
Hmmm this is a NOOP did you mean to do that?


for i in "*.html" is the same as i="*.html" so your loop is doing no 
work at all, so this same as

sed -i -e 's/fish/chips/g' *.html

Which was the "right" answer.

 
[oolon at osiris example]$ ls -l
total 0
-rw-r--r--. 1 oolon ankh 0 Nov 15 10:50 abc 123.html
-rw-r--r--. 1 oolon ankh 0 Nov 15 10:50 fred.html
-rw-r--r--. 1 oolon ankh 0 Nov 15 10:50 fred.text

Your answer

[oolon at osiris example]$ for i in "*.html"; do echo $i; done
abc 123.html fred.html

"Right" answer for a loop
[oolon at osiris example]$ for i in *.html; do echo "$i"; done
abc 123.html
fred.html
[oolon at osiris example]$


James
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list