VALID_PASSWORD="secret" #this is our password.
echo "Please enter the password:"
read PASSWORD
if [ "$PASSWORD" == "$VALID_PASSWORD" ]; then
echo "You have access!"
else
echo "ACCESS DENIED!"
fi
Comparisons:
-eq | equal to |
-ne | not equal to |
-lt | less than |
-le | less than or equal to |
-gt | greater than |
-ge | greater than or equal to |
File Operations:
-s | file exists and is not empty |
-f | file exists and is not a directory |
-d | directory exists |
-x | file is executable |
-w | file is writable |
-r | file is readable |
-n | tests to see if the argument is non empty |
X=""
# -n tests to see if the argument is non empty
if [ -n $X ]; then
echo "the variable X is not the empty string"
fi
if [ "$AGE" -lt 20 ] || [ "$AGE" -ge 50 ]; then
echo "Sorry, you are out of the age range."
elif [ "$AGE" -ge 20 ] && [ "$AGE" -lt 30 ]; then
echo "You are in your 20s"
fi
if [[ $count -gt 0 && $somevar != $var ]]; then
...no brackets inside, only double [[ ]]
fi
if [ $count -gt 0 ] && [ $somevar != $var ]; then
...do something
fi
No comments:
Post a Comment