Created
October 26, 2012 16:02
-
-
Save saltnlight5/3959625 to your computer and use it in GitHub Desktop.
bash_programming.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number comparison: [[ -gt, -ge, -lt, -le ]] | |
# Number comparison: (( <, <=, >, >= )) | |
# String comparison: [[ ==, != ]] | |
# String comparison: -z zero_length_string, -n not_zero_length_string | |
# String comparison: | |
[[ $a == z* ]] # True if $a starts with an "z" (pattern matching). | |
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching). | |
[ $a == z* ] # File globbing and word splitting take place. | |
[ "$a" == "z*" ] # True if $a is equal to z* (literal matching). | |
# Repeat N times | |
for N in {1..3}; do | |
echo "Repeating $N times." | |
done | |
for (( N=0; N<3; N++ )); do | |
echo "Repeating $N times." | |
done | |
# Check to see if we are in Cygwin env | |
if [[ $OS == Windows* ]]; then | |
echo "We in Windows/cygwin shell." | |
else | |
echo "We are in non Windows/cygwin shell." | |
fi | |
# Default N=0, if arguments[0] given, then assign it. | |
function atest() { | |
N=0 | |
if [[ $# -ge 1 ]]; then | |
N=1 | |
fi | |
echo "Parameter N=$N" | |
} | |
# Loop through a constant list | |
LIST=" | |
one | |
two | |
three" | |
for N in $LIST; do | |
echo $N | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment