ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/bash
while [ 1 ]; do
LIST=$(ls *wav)
for i in $LIST; do
play $i
sleep 10
done
done
OK. When this script is running, I want to stop it whenever I want, for example with ^C. But ^C wont do. I think maybe substituting something like a read bultin command in the while argument would be a solution. Does read wait for the Return key?
#!/bin/bash
kill_script ()
{
echo "SIGTERM received, exiting..."
exit
}
trap kill_script SIGINT SIGTERM
while [ 1 ]; do
LIST=$(ls *wav)
for i in $LIST; do
play $i
sleep 10
done
done
Environment variables are generally all upper-case. So while not absolutely necessary, it's good practice to keep your own user variables in lower-case or mixed-case, to help differentiate them.
Code:
#!/bin/bash
kill_script ()
{
echo "SIGTERM received, exiting..."
exit
}
trap kill_script SIGINT SIGTERM
while true; do
list=( *.wav ) # If it's not necessary to regenerate the list
# every time it loops, leave this step outside.
for i in "${list[@]}"; do # or just use "for i in *.wav" here.
play "$i"
sleep 10
done
done
Last edited by David the H.; 01-31-2012 at 08:35 AM.
Does Ctrl+C work if you put the sleep 10 in the background and wait for it? Like this sample from lm_sensors' fancontrol script (the "Sleep while still handling signals" comment has always intrigued):
Code:
while true
do
UpdateFanSpeeds
# Sleep while still handling signals
sleep $INTERVAL &
wait $!
done
I'am using linux fedora and mandrake. So I must forget kbhit(), even if some DOS emulators can run it but I don't want that. I did some seaching about termios and it seem to be very complex to use.
Environment variables are generally all upper-case. So while not absolutely necessary, it's good practice to keep your own user variables in lower-case or mixed-case, to help differentiate them.
Code:
#!/bin/bash
kill_script ()
{
echo "SIGTERM received, exiting..."
exit
}
trap kill_script SIGINT SIGTERM
while true; do
list=( *.wav ) # If it's not necessary to regenerate the list
# every time it loops, leave this step outside.
for i in "${list[@]}"; do # or just use "for i in *.wav" here.
play "$i"
sleep 10
done
done
Thank you very much for your tips. About variable substitution I've had long correspondence in the forum. It seems to be a golden rule.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.