3 ms·
This one, probably: # CORRECT su root -c 'rm "$@"' -- "$@" rm "one two" "three four" The command is going to be evaluated by bash, with ARGV set t
by floatingatoll 7y ago
This one, probably:
# CORRECT
su root -c 'rm "$@"' -- "$@"
rm "one two" "three four"
The command is going to be evaluated by bash, with ARGV set to what you pass after the hyphens as arguments to the bash environment that su spawns. Passing the arguments to su using "$@" to encode your calling function’s ARGV ensures that they’re uncorrupted into the su-spawned bash environment’s ARGV, and then executing the literal command rm "$@" ensures that they’re uncorrupted into the spawned rm command’s ARGV.
You could fake this with printf %q if you tried hard enough but that’s a high-risk game to diagnose issues with, for example when you’re trying to figure out why newlines are reaching the command as the letter n.