Sleep command is used to delay for a fixed amount of time during the execution of any script. When the coder needs to pause the execution of any command for the particular purpose then this command is used with the particular time value. You can set the delay amount by
A system to let only some of the players on a server sleep in order to skip the night. This was done for a request from one of my viewers. To install, just run the command and then select a percentage using the command /scoreboard players set Percentage Sleep YourNumberHere. Nov 24, 2010 Kingdom Hearts - Birth By Sleep Command Charge List Guide (Translated) Created by: lillamb Version 6.0 - 26 June 2010 - Interpretation Errors fixed - REVENGE COMMANDS updated.
seconds (s), minutes (m), hours (h) and days (d). This tutorial will help you to learn the use of sleep command by using different bash scripts.Sleep command syntax:
sleep number[suffix]
You can use any integer or fractional number as time value. Suffix part is optional for this command. If you omit suffix then time value is calculated as seconds by default. You can use s, m, h and d as suffix value. The following examples show the use of sleep command with different suffixes.
Example-1: sleep command without any suffix
In the following script, sleep command is used with numeric value 2 only and no suffix is used. So, if you run the script then the string “Task completed” will print after waiting for 2 seconds.
echo'Waiting for 2 seconds...'
sleep2
echo'Task Completed'
Run the bash file with time command to show the three types of time values to run the script. The output shows the time used by a system, user and real time.
Output:
Example-2: sleep command with a minute suffix
In the following script, ‘m‘ is used as the suffix with sleep command. Here, the time value is 0.05 minutes. After waiting 0.05 minutes, “Task completed” message will be printed.
How To Get More Commander Slots In Birth By Sleep
echo'Waiting for 0.05 minutes...'
sleep 0.05m
echo'Task Completed'
Run the script with time command like the first example.
Output:
Example-3: sleep command with hour suffix
In the following script, ‘h‘ is used as the suffix with sleep command. Here, the time value is 0.003 hour. After waiting 0.003 hour “Task completed” should be printed on the screen but it requires more times in reality when ‘h’ suffix is used.
echo'Waiting for 0.003 hours...'
sleep 0.003h
echo'Task Completed'
$ timebash sleep3.sh
Output:
Example-4: sleep command with loop
You can use sleep command for various purposes. In the following example, sleep command is used with while loop. Initially, the value of the variable n is set to 1 and the value of n will be incremented by 1 for 4 times in every 2 seconds interval. So, when will you run the script, each output will appear after waiting 2 seconds.
n=1
while[$n-lt5]
do
echo'The value of n is now $n'
sleep 2s
echo' '
((n=$n+1))
done
Output:
Example-5: sleep command in the terminal with other commands
Suppose, you want to run multiple commands and set the fixed time interval between the outputs of two commands, then you can use sleep command to do that task. In this example, the command ls and pwd are with sleep command. After executing the command, ls command will show the directory list of the current directory and show the current working directory path after waiting for 2 seconds.
Output:
Example-6: Using sleep command from the command prompt
sleep command is used between two echo commands in the following example. Three time values will be displayed after executing the command.
Output:
sleep command is a useful command when you need to write a bash script with multiple commands or tasks, the output of any command may require a large amount of time and other command need to wait for completing the task of the previous command. For example, you want to download sequential files and next download can’t be started before completing the previous download. In this case, it is better to sleep command before each download to wait for the fixed amount of time.
There are two commands which we can use to make a batch command sleep for some time. The native available ‘timeout’ command and the resource kit tool ‘sleep’.
Timeout command
We can use ‘timeout’ command in Windows 7 to pause execution for some time and then continue. We can specify the number of seconds to wait, it would wait till the time elapses or until user presses any key.
Example: To wait for 10 seconds
Example: To sleep for 2 minutes and ignore any key presses
Sleep command
Windows provides a resource kit tool ‘sleep’ which can be used in batch files or command prompt to pause the execution and wait for some time. Though the tool was intended for XP, I have used it on Windows 7 and it works perfectly fine. Find the download location and installation instructions here :Download Windows resource kit tools .
Syntax of sleep command:
(or)
Birth By Sleep Command Slots
Examples:
If you want to pause the execution of a batch file for 50 seconds, then you should insert below statement in your batch file.
If you want to wait for 100 milli seconds, then you can run the below command.
Birth By Sleep Command Styles
Sleep command should also work find on Server 2008 and Server 2008 R2.
Birth By Sleep Command Guide
Also Read:Windows commands