Last active
August 29, 2015 14:16
-
-
Save tung-dang/343108e4db7f28e88c4c to your computer and use it in GitHub Desktop.
bash collections
This file contains 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
# check if a directory exists in a shell script you can use the following: | |
if [ -d "$DIRECTORY" ]; then | |
# Control will enter here if $DIRECTORY exists. | |
fi | |
#Or to check if a directory doesn't exist: | |
if [ ! -d "$DIRECTORY" ]; then | |
# Control will enter here if $DIRECTORY doesn't exist. | |
fi | |
#find the double-bracket version of test makes writing logic tests more natural: | |
if [[ -d "${DIRECTORY}" && ! -L "${DIRECTORY}" ]] ; then | |
echo "It's a bona-fide directory" | |
fi |
This file contains 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
# If we are on a mac, lets install and setup homebrew | |
if [ "$(uname -s)" == "Darwin" ] | |
then | |
info "installing dependencies" | |
if . bin/dot > /tmp/dotfiles-dot 2>&1 | |
then | |
success "dependencies installed" | |
else | |
fail "error installing dependencies" | |
fi | |
fi |
This file contains 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
# loop all file in $HOME and printing each item | |
for item in $HOME/*; do | |
if [ -f "$item" ]; then | |
cat "$item" | |
fi | |
done | |
# print 0 --> 9 | |
num=0 | |
while [ $num -lt 10 ]; do | |
echo $num; | |
num=$((num + 1)) # <=> `expr $num + 1`` | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment