4 ms·
su root -c 'rm "$@"' -- "$@" The first instance ('rm "$@"') is part of the argument to -c. It is the "command" that su will have the spawned shell execute. T
by pwg 7y ago
su root -c 'rm "$@"' -- "$@"
The first instance ('rm "$@"') is part of the argument to -c. It is the "command" that su will have the spawned shell execute. The single quotes around the entire command pass the whole command, unchanged, onward to the shell that will be spawned, so that what is executed by that spawned shell is rm "$@" .
The second instance is the argument list being given to su by the shell running the su, and it is just normal "$@" semantics there. One has to realize here that the second "$@" is being expanded by the current shell (the one running su) while the first "$@" is not expanded by the current shell, but is instead expanded by the spawned shell.
The "$@" is needed twice, because two expansions ultimately take place, the first expansion occurs in the current shell, the second one is delayed and occurs in the spawned shell.
- hinkley 7y agoI had to read this several times before it sunk in, and in fact had to start formulating a follow up question before the bulb turned on. The first expansion is in the first process, second expansion in the child. So $@ number two is the input to $@ number one.