Код: Выделить всё
Condition Equivalent
$a -lt $b $a < $b
$a -gt $b $a > $b
$a -le $b $a <= $b
$a -ge $b $a >= $b
$a -eq $b $a is equal to $b
$a -ne $b $a is not equal to $b
-e $FILE $FILE exists
-d $FILE $FILE exists and is a directory.
-f $FILE $FILE exists and is a regular file.
-L $FILE $FILE exists and is a soft link.
$STRING1 = $STRING2 $STRING1 is equal to $STRING2
$STRING1 != $STRING2 $STRING1 is not equal to $STRING2
-z $STRING1 $STRING1 is empty
Код: Выделить всё
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Error: Invalid number of arguments"
exit 1
fi
file=$1
if [ -f $file ]; then
echo "$file is a regular file."
elif [ -L $file ]; then
echo "$file is a soft link."
elif [ -d $file ]; then
echo "$file is a directory."
else
echo "$file does not exist"
fi
Код: Выделить всё
#!/bin/bash
CHAR=$1
case $CHAR in
[a-z])
echo "Small Alphabet." ;;
[A-Z])
echo "Big Alphabet." ;;
[0-9])
echo "Number." ;;
*)
echo "Special Character."
esac
Код: Выделить всё
#!/bin/bash
if [ $(whoami) = 'root' ]; then
echo "You are root"
fi