In this example, the script displays the message “Starting” , then pauses execution for 5 seconds using the sleep command , and finally displays the message “Finishing” .
Additionally, the sleep command also accepts arguments in other time units, such as minutes ( m ), hours ( h ), and days ( d ). Example
Note that the sleep command is a shell builtin, meaning it is not a standalone command, but a feature available in most Unix-like shells, such as bash, ksh, zsh , and others.
Check if a file exists
Here is an example of a Shell Script that uk cell phone number list checks whether a specific file exists or not:
This script uses the if command to check if the file specified in the file variable exists. The condition [ -e "$file" ]is used to check if the file exists.
The -e parameter is an option to the test command or the brackets [ ]that checks if the file exists and is readable .
If the file exists, the message “The file example.txt exists” will be displayed.
If the file does not exist, the message “The file example.txt does not exist” will be displayed.
Also, the variable file is defined as the first parameter passed to the script ( $1). This means that when you run the script, you must provide the fi
If the file “example.txt” exists, the message “The file example.txt exists” is displayed .
Otherwise, the message “The file example.txt does not exist” is displayed.
Example of how to use the sleep command:
-
- Posts: 43
- Joined: Sat Dec 21, 2024 5:52 am