Im making a bash script where I have to wait for a few seconds (max 10) then run a few commands. This is because when a program is started, it also starts a few useless subprocesses which I don't need. But as I said, it takes a few seconds for these to start, so what I did was this:here is where the program is started && sleep 20 && kill `ps -x | grep explorer.ex[e] | awk '{print $1}'` && kill `ps -x | grep winewrapper.ex[e] | awk '{print $1}'`But after the sleep it just falls a sleep, it doesnt run the kill commands, and instead I have to run them manually which away the point of this script. What am I supposed to do? Am I using the sleep command wrong?EDIT: Since this question is being asked to be closed I though that I would clarify.The sleep process does not wake up and the pkill commands are not run. Here is my entire script  (It's AppleScript, but I'm running unix scripts from the AppleScript):do shell script killall applet && cd /Applications/Dishonored.app/Contents/Resources/Dishonored/Binaries/Win32 && /Applications/CrossOver.app/Contents/SharedSupport/CrossOver/bin/wine --bottle ny\\ flaska\\ 2 Dishonored.exe && sleep 20 && kill `ps -x | grep explorer.ex[e] | awk '{print $1}'` && kill `ps -x | grep winewrapper.ex[e] | awk '{print $1}'`What can I do to make sleep wake up and continue the pkill commands after 20 seconds?
sleep command not doing what it is supposed to do?
shell script;kill
It's not clear what you're asking, but I see several possible sources of problems here.Let's get your overly complicated kill commands out of the way up front. This isn't the actual problem, but it will make the rest of the answer  and your eventual solution  clearer if you switch to pkill. It does the same thing as your ps+grep+awk+kill pipeline within a single command. It is not only more efficient and easier to type, it doesn't require any regex trickery to filter the grep command out of the ps results, which is a common mistake that causes the pipeline to get broken early, leaving processes running that should be killed. Your grep pattern avoids this mistake, but it's easy to forget the need. I see from your question that you are on OS X, so you do have pkill. You need to match on arguments to the command instead of on the process name, but you can do that with the -f flag.With that out of the way, the first likely source of your problem is that your initial command may be exiting with an error code. Because you are using the && operator, subsequent commands will only be run if the first one returns a 0 exit code, meaning no error. If you want these commands to run regardless, you need to use ; instead:./myprogram ;      sleep 20 &&      pkill -f explorer.exe &&      pkill -f winewrapper.exeNotice that it is possible to mix both styles. We are saying, Run myprogram unconditionally, wait for it to exit, then run the rest of these things, all of which have to return successfully to continue through the chain of commands. sleep will never fail, but if the first pkill step can fail and you want the second one to run regardless, switch the second && to ;, too.The other possibility is that you are expecting these kill commands to run while Wine/CrossOver is still running Dishonored.exe. That is, you want the killin' to start 20 seconds after Wine starts, not 20 seconds after it exits. Unless this program forks itself off into the background, you're going to get the latter behavior. If you want the parallel behavior, you need to background the first program:./myprogram &      sleep 20 &&      pkill -f explorer.exe &&      pkill -f winewrapper.exeThe & terminates the first command much like ; in the previous example, except that the rest of the command string begins running as soon as myprogram starts.