Bash/terminal-issue


lomaxx

Active Member
Joined
Sep 22, 2008
Messages
747
I tried to build myself a minimal launcher-menu that i can launch on a shortkey (through xbindkeys) and then run scripts/commands depending on another key i press (like "1" for "wlan on"+"start network-manager"+"nm-applet"). For that i run a simple bashscript with the help of "xterm -e".


My problem is that I do not manage to make a program run in the background, like nm-applet, after the script has quit. When i run nm-applet in the foreground, then the script does not end and the menu is shown. If i run it in the background (nm-applet &) then nm-applet starts, but is killed once the rest of my menu-script runs through. I tested this by adding a "sleep 5s" after the line for nm-applet.


By now i also tested other applications than nm-applet. So this is is not related only to this command. It's somehow related to the fact that i am using "xterm -e" (I also tried other terminals). Because when i open a terminal manually instead, run "nm-applet &" and close the terminal with ctrld+d, then nm-applet keeps running. Even when i run my menuscript from a terminal manually then nm-applet keeps running. Just when i run "xterm -e menuscript.sh" nm-applet quits once the script ran through.


Here is a small test that you can use if you want to experience the same:


- open a terminal


- run "zenity --info &" to show an example-window of zenity (ignore the "update"-text, it's just an example). The window will stay open and only close once you click ok.


- create a simple script. For example by entering "touch test.sh", "chmod +x test.sh" and editing the file the following way:



Code:
#!/bin/bash

zenity --info &

sleep 3s


- run that script ("./test.sh"). You will notice that the window will still stay open until you click "ok".


- run "xterm -e test.sh" (or "terminal -e test.sh"). After 3 seconds the window will close.


I tried to find a solution on my own. Found stuff like "disown" (bash-command), tried subshells "(nm-applet)&", tried sub-scripts, but nothing helps. Maybe it would work to run the command not as sub-process but I have no idea how to make it run as parallel process.


Anyone got a clue?
 
Last edited by a moderator:
Someone (<Riviera>) from freenode-irc in #bash, who seems to be a Pandora owner too (what a coincidence) was kind enough to help me out. The solution is to use "set -m". before the command is run. Works fine so far. Thanks to him/her.


Oh and I was informed by someone else that it's not good to name bash-scripts ".sh" at the end. Reason:

Don't use extensions for your scripts. Scripts define new commands that you can run, and commands are generally not given extensions. Also: bash scripts are *not* sh scripts (so don't use .sh) and the extension will only cause dependencies headaches if the script gets rewritten in another language.
 
Last edited by a moderator:
Another way I know of is using the keyword disown after the &. It works in ubuntu and I'd be surprised if it didn't work on the pandora.


-Neelix
 
Back
Top