NEW: Added if-usage.sh showing various use of the if statement
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if ls -d /tmp; then
|
||||||
|
echo "Command succeeded: file exists."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /etc/hosts ]; then
|
||||||
|
echo "/etc/hosts exists"
|
||||||
|
fi
|
||||||
|
|
||||||
|
num=100
|
||||||
|
if [ "$num" -gt 10 ]; then
|
||||||
|
echo "The number is greater than 10."
|
||||||
|
fi
|
||||||
|
|
||||||
|
floatnum=20.34
|
||||||
|
result=$(echo "$floatnum > 10.5" | bc)
|
||||||
|
if [ "$result" -eq 1 ]; then
|
||||||
|
echo "The number is greater than 10.5"
|
||||||
|
fi
|
||||||
|
|
||||||
|
word="hello"
|
||||||
|
if [ "$word" = "hello" ]; then
|
||||||
|
echo "You typed hello."
|
||||||
|
fi
|
||||||
|
|
||||||
|
sentense="I want to say hello to the world"
|
||||||
|
regex="say.*hello"
|
||||||
|
if [[ "$sentense" =~ $regex ]]; then
|
||||||
|
echo "Substring found."
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user