Bash If / Else
Conditional logic lets scripts take different paths based on tests.
Example
#!/bin/bash
FILE="example.txt"
if [[ -f "$FILE" ]]; then
echo "Found $FILE"
else
echo "Creating $FILE"
echo "Hello" > "$FILE"
fiHow to run it
- Save it to a file.
- Run
chmod +x filename.shwhere applicable. - Run it from the terminal.