3 ms·
Pretty much all listed examples ignore quoting, especially the suggested replacements, proving opportunities for argument confusion and many are vulnerable to c
by labawi 5y ago
Pretty much all listed examples ignore quoting, especially the suggested replacements, proving opportunities for argument confusion and many are vulnerable to command injection.
Piping data that may be hostile or just accidentally dangerous into bash seems like a bad idea. At least xargs will execute the command you specified.
You should use find, or find -print0 | xargs -0. Then your file names will be parsed correctly.
echo accidental > 'apartment /home building.odt'
echo malicious > 'bobby -rf --no-preserve-root / foo'
echo bash > "$(printf "foo\n echo pipe injection)"
rm $(ls | grep foo) # bye bye system
ls | grep foo | sed 's/.*/rm &/' | bash # injection
ls | grep foo | xargs rm # dangerous though moderately constrained
rm *foo* # ok
find . -maxdepth 1 -iname '*foo*' -delete # ok
find . -maxdepth 1 -print 0 | grep --null foo | xargs -0 rm # ok