I am working on client and want to run a script on server which includes a trap.
The following minimal example works fine if I connect to server and run it in an interactive SSH session:
user@client:~$ ssh user@server
user@server:~$ sh -c 'trap "echo exiting..." EXIT'
exiting...
user@server:~$
However, if I don't connect to server interactively, but add the command to the ssh command, it doesn't work anymore:
user@client:~$ ssh user@server -- sh -c 'trap "echo exiting..." EXIT'
user@client:~$