Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created May 26, 2011 16:00
Show Gist options
  • Save xeoncross/993418 to your computer and use it in GitHub Desktop.
Save xeoncross/993418 to your computer and use it in GitHub Desktop.
BASH coding
# To check if a directory exists in a bash 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
# Search for string in a file
if grep -q PATTERN FILE; then
echo "Found"
fi
# http://en.wikipedia.org/wiki/Here_document#Unix-Shells
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment