I'm trying to prevent Ctrl-C from interrupting a command I want to run in the terminal using `su - -c`. Should I use the command as `su - -c 'trap "" INT; some_command'` or `trap '' INT; su - -c 'some_command'; trap - INT`? What are the differences between these two methods?
1 Answer
It might be better to put the trap inside the subshell using the first approach. It seems cleaner semantically, and according to the `su` documentation, when you switch to superuser, `su` automatically blocks SIGINT and SIGQUIT. That way, you won’t have to worry about those signals affecting the `su` process itself.
Are you saying that with `su -`, those signals don't affect the new root shell? And when using `-c`, they are not blocked? That fits my experience! Also, does the pre-existing trap still affect the subshell if it's under a different user?