Reputation: 17
I need a command within a shell script to wait for a while, is there a way how to use sleep so that it would run only within the script and I wouldn't have to wait until it is done?
Upvotes: 0
Views: 569
Reputation: 158010
Run it in background using the &
:
sleep 10 &
If want it to do something useful you can launch multiple commands in a sub shell:
(echo start; sleep 10 ; echo end) &
Or even write a shell script:
script.sh:
#!/bin/bash
echo "start"
sleep 10
echo "end"
and launch that in the background:
chmod +x script.sh
./script.sh &
Further reading:
Upvotes: 0
Reputation: 53310
You can run the entire script in the background with &
:
$ ./<scriptname> &
Which sounds like what you want to do.
Upvotes: 1