[CentOS] bash - safely pass untrusted strings?

Jacques B. jjrboucher at gmail.com
Tue Feb 26 22:30:12 UTC 2008


>  Unless I'm terribly mistaken (again?), the only way I've been able to
>  see "loop thru a list of files" work reliably is with "find" using
>  the "-print0" option, in cahoots with xargs.
>
>  Is there any other way?
>
>
>  -Ben
>  --

If I understand you correctly, you are referring to the problem caused
by spaces in filenames?  Steve mentioned the environment variable IFS
("individual field separator" if memory serves me correctly).  By
default it's space, tab, or newline.  You can change that in your
script to be newline only in order to process file names with spaces
in it, and then change it back afterwards (so save the value of $IFS
at the beginning of the script to something like Default_IFS and then
just prior to exiting the script reassign that value back to IFS to
return it to its original state).  If that's what you are looking at
doing I'm sure someone here can fill in the blanks on that one.  If
not when I get to the office tomorrow I can have a look at some of my
scripts where I had to do that and post sample code for you.

Jacques B.



More information about the CentOS mailing list