When you source the file with .
, the commands will run just as if you had entered them in the command line. Thus exit
will exit your currently running shell.
To exit the shell from which the script was executed when forking, you need to get the process id of the parent process. You can try running
kill $
in the script instead of exit
to kill the parent shell (tip: try just echoing the pid first and check which process it corresponds to so you don't kill your WM or something).
If $
doesn't do it for you, you can also try sending the pid as a parameter to the script, but it depends on how and where it's called.
You said you used urxtvd
/urxvtc
. With that combination, this script kills the terminal from which it was started:
#!/bin/sh echo kill in 3 sleep 3 kill -1 $
so you should be able to use kill -1
in this way to kill a single urxvtc
instance.
Note that if you run this by sourcing, then the urxvtd
instance will be $PPID
for the currently running terminal, and all terminals will die. You don't want that.