passing commands as arguments to functions in bash script
Hello,
I wrote a simple bash script to let me treat any set of programs like a deamon. For example if I configure the script a certain way I can start/stop/get the status of apache, mysql and php all from one command. I am having a bit of a problem though. I am passing commands as strings to a function and then depending on the arguments to the script it might run one of these commands or another. Some of these commands need to be run in the background though, such as deluge-web. When I send "deluge-web &" to the function and it execute it deluge-web does not start in the background. I can't figure out why this is. I have tried escaping the & with ''s and with a \, but nothing seems to work. I know that this is some idiotic thing that I am overlooking, but I am a bit stumped. Here is the script configured to start/stop/get status of deluged and deluge-web. Thanks for your help. Code:
#!/bin/bash |
Throwing in an eval works:
sage@mercury:~$ echo boo > 'a b' sage@mercury:~$ x="gedit 'a b' &" sage@mercury:~$ eval $x [1] 7944 <-- launched in background sage@mercury:~$ |
Have you tried your commands on the command line? This is what I got for a little test using find:
Code:
rob:~$ arg="find . -name a.out &" Is there a need to pass the ampersand? Could you not add it to the line where the command contained in $todo is executed?: Code:
$todo & |
Tischbein: Wonderful. This works great. Thanks!
Robhogg: You seem to be right about the way the ampersand works. I suppose that I don't really need the ampersand in the string. Thanks! |
All times are GMT -5. The time now is 08:51 AM. |