last day (15 days later) » 

9:29 PM
1
A: Exit terminal after running a bash script

heemaylThe simplest solution would be: nohup xdg-open file.pdf && exit nohup causes the xdg-open command to run ignoring SIGHUP, so if the terminal is closed it has no effect on the xdg-open command. && indicates the next command will be run if the previous command is successful i.e. returns the exi...

 
@Tim: Perhaps OP did not use it the right way, from the question its very unclear to me how did he/she put exit at the end and did not work..
 
kos
@Tim Because OP put exit inside the script, which is unuseful because it has the effect of exiting the bash instance in which the script is being executed rather then the parent bash instance (the one linked to the Terminal), which would cause the Terminal to close instead
Anyway xdg-open runs already in the background and unlinked from the the Terminal, so you don't need nohup here, plus from what I understand OP runs xdg-open multiple times inside a script to batch-open multiple files, using xdg-open like that inside the script would cause the script to exit at the first xdg-open occurence
 
@kos: No, i am not running xdg-open in the backgr, even if i had nohup is for a different reason & must be there..any background process from originating terminal will be killed when you will kill the parent terminal..nohup is there to prevent it..as i don't need to use the terminal interactively again, there is no need to put the process in bg..on your 2nd point that can also be prevented by running each xdg-open && exit in a subshell..
 
kos
There's no need for nohup, just try touch test.txt && xdg-open test.txt && exit, the Terminal will be closed and gedit will stay opened. My second point was about the fact that OP has a script with multiple xdg-open commands, and running each of them chained with exit will cause the script to exit at the first occurence
 
@kos I think you are confused between & and &&..try running gedit test.txt && exit......xdg-open test.txt && exit works because xdg-open will open the file with the preferred application and then the terminal will exit with xdg-open being the process being killed (check that with ps) leaving the gedit or whatever the preferred app open..(although i need to work on this explanation in details)..
 
kos
9:29 PM
No I'm not confused between & and &&, try touch test.txt && xdg-open test.txt && jobs -l, there's no background process for xdg-open, so it doesn't need either & disown or nohup
 
@kos First of all, could you please check what command i have used, there is no & in my command, secondly in my last comment i think i have answered your last question (why there is no xdg-open & why you can work without nohup in this particular case)..also nohup is for different reason as i have already mentioned..
 
kos
Sorry, my latest example was wrong, but I've never stated there's an & in your command... In your last comment you said "xdg-open test.txt && exit works because xdg-open will open the file with the preferred application and then the terminal will exit with xdg-open being the process being killed", what I'm trying to say it's that xdg-open is not getting killed, because it exits on his own once it has done what it had to, so it's unuseful to use either & disown (which you didn't do) or to use nohup (which is what you did)
 
No problem....
 
kos
Hi heemayl
 
what i meant is only hypotrhetical and i need to work on that....
hi
if you do gedit file && exit .....it won't work and also will be killed if the terminal is closed..there comes nohup and &
 
kos
9:33 PM
I agree, what I meant is that xdg-open exits pretty much like echo does
 
but in this particular case i am really wondering why nohup is not needed....
it spawns a subprocess before spawning..
i mean exiting
 
kos
Yes that's what I think
Perhaps it does the equivalent of nohup on his own
 
then if you can't do it with a single process like gedit file.txt, why its possible for xdg-open.....only logical explantion is because it spawns a subprocess that is not being killel
*kiled
let me trace some syscalls
 
kos
Ok :) To explain this behavior I think that xdg-open could be compared to a bash script which runs this command: nohup bash -c '$1' && exit
 
9:48 PM
well, SIGCHLD is issued as expected ..i think the conclusion could be that as xdg-open has exited with spawning a child..the actual process started from the terminal is no longer there to be killed..so actually nohup is not needed..
 
kos
Yep, also ps aux | grep xdg-open doesn't report anything
 
yeah..
ok..let me edit my answer putting this info
 
kos
Ok :) also in my opinion it's not clear whether OP is opening multiple files or not, it looks like it's doing so... maybe someone should suggest him to not use a bash script if he's issuing a single command
 
edited..yes..its pretty vague..also i think OP is not coming back either in a short time as he has already accepted an answer :P
 
kos
Yep i think so as well
They never come back. I'm leaving a comment to see if he eventually will explain what he wants
 
10:01 PM
yeah..that should do..
ok..it was nice talking to you..see ya :)
 

last day (15 days later) »