if else in shell script example | Conditions in bash scripting (if statements) | Shell Scripts

198 views Oct 29, 2023
publisher-humix monibe.com

Here is a simple example of an if-else statement in a shell script: Bash #!/bin/bash # Check if the file "myfile.txt" exists if [ -f myfile.txt ]; then # The file exists echo "The file myfile.txt exists." else # The file does not exist echo "The file myfile.txt does not exist." fi Use code with caution. Learn more This script will check if the file "myfile.txt" exists. If it does, the script will print the message "The file myfile.txt exists." Otherwise, the script will print the message "The file myfile.txt does not exist." Here is another example of an if-else statement in a shell script: Bash