General TC > General TC Talk

scripting q-- wait for response?

(1/6) > >>

How would i delay/sleep a bash script to wait until a command has given a return? For example, the 'mpc idle' command only returns when something changes, driven by external events. So i don't think it works the same way as waiting for a program to complete.

That is the default behavior.
If you want a script to start a program and NOT wait for it to terminate, you must use '&' to run it in background.

ok, well this is my script;

--- Code: ---while true
        read line < /usr/local/bin/mpc idle
        if [ $line == "player" ]; then
                sudo echo 'not'
                sudo echo 'idle'
        sleep 0.2

--- End code ---

and it echo's 'idle' every .2 seconds. (NB without else or sleep it doesn't do anything, even with external events firing)
in case you are not familiar; 'mpc idle' will return 'player' when an external event changes something with mpd. Until that, it doesn't return anything.

This really is not a bash forum, but

read line < /usr/local/bin/mpc idle
tries to read from the file /usr/local/bin/mpc

line=`/usr/local/bin/mpc idle`
line=$( /usr/local/bin/mpc idle )

Well thanks for replying anyway. I would urge a general linux sub-forum to filter out these questions from those who don't want to see them.

I have a slightly more tinycore related follow up.. if i try and run this script in eg., it doesn't work. However if i run it after, it does. How can i get it to work automatically on boot?


[0] Message Index

[#] Next page

Go to full version