Skip to content

Instantly share code, notes, and snippets.

@tung-dang
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tung-dang/343108e4db7f28e88c4c to your computer and use it in GitHub Desktop.
Save tung-dang/343108e4db7f28e88c4c to your computer and use it in GitHub Desktop.
bash collections
# 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
# 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
# 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