[ALUG] Wildcards gone wild

Howard L Frederick simbamangu at gmail.com
Fri Jun 27 19:20:07 EAT 2014


That was going to be my next question, how to prevent it. Thanks!

On 27 June, 2014 at 19:18:24, Andreas Tauscher via Linux (linux at lists.habari.co.tz) wrote:

Am 06/27/2014 06:00 PM, schrieb Howard L Frederick:
> That is seriously scary.

But easy to prevent:

* Double-quote all variable references and command substitutions.
Instead $var use "$var"
* Set IFS to just newline and tab IFS="$(printf '\n\t')"
* Prefix all path/file names with ./ so they cannot expand to begin with
“-”. "rm *" will expand a file named -rf to
rm file1 file2 file3 ..... -rf
rm ./* will expand to
rm ./file1 ./file2 ./file3 ..... ./-rf
* Be careful about file names. They might contain control characters,
not printable character. Filtering out all not printable chars can be
done with something like this: printf '%s' "$file" | LC_ALL=POSIX tr -d
'[:cntrl:]' | iconv -cs -f UTF-8 -t UTF-8


_______________________________________________
The Arusha Linux User Group: http://unix.or.tz
Linux mailing list
Linux at lists.habari.co.tz
http://lists.habari.co.tz/cgi-bin/mailman/listinfo/linux

The Arusha LUG mailing list is generously hosted by Habari Node Ltd: http://www.habari.co.tz/

The above comments and data are owned by whoever posted them (including attachments if any). The mailing list host is not responsible for them in any way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.habari.co.tz/pipermail/linux/attachments/20140627/ad8c0e6f/attachment-0001.html>


More information about the Linux mailing list