Bash-statements
Материал из Ksimute
Содержание |
Забываю их с завидной регулярностью, т.к. на баше пишу мало потом судорожно ищу в гугле. :)
Arithmetic Comparisons
-lt < -gt > -le <= -ge >= -eq == -ne !=
пример скрипта
#!/bin/bash # declare integers NUM1=2 NUM2=2 if [ $NUM1 -eq $NUM2 ]; then echo "Both Values are equal" else echo "Values are NOT equal" fi
String Comparisons
= equal != not equal < less then > greater then -n s1 string s1 is not empty -z s1 string s1 is empty
пример скрипта
#!/bin/bash #Declare string S1 S1="Bash" #Declare string S2 S2="Bash" if [ $S1 = $S2 ]; then echo "Both Strings are equal" else echo "Strings are NOT equal" fi
Bash File Testing
-b filename Block special file -c filename Special character file -d directoryname Check for directory existence -e filename Check for file existence -f filename Check for regular file existence not a directory -G filename Check if file exists and is owned by effective group ID. -g filename true if file exists and is set-group-id. -k filename Sticky bit -L filename Symbolic link -O filename True if file exists and is owned by the effective user id. -r filename Check if file is a readable -S filename Check if file is socket -s filename Check if file is nonzero size -u filename Check if file set-ser-id bit is set -w filename Check if file is writable -x filename Check if file is executable
гугл впоиске выдал на тему http://www.linuxconfig.org/Bash_scripting_Tutorial