Skip to content

Instantly share code, notes, and snippets.

@antonfisher
Last active November 20, 2015 09:17
Show Gist options
  • Save antonfisher/bc7f79ee5c7211bc05cb to your computer and use it in GitHub Desktop.
Save antonfisher/bc7f79ee5c7211bc05cb to your computer and use it in GitHub Desktop.
BASH: check_directory_exits
##
# Check directory
# $1 {String} - path
# $2 {Number} - show error
#
# @returns {Number} 0 - exists / 1 - not exists
#
# Example:
# check_directory_exits /tmp 1;
#
function check_directory_exits {
if [[ -d "$1" ]]; then
return 0;
else
if [[ "$2" == 1 ]]; then
echo -e "Directory '$1' does not exist. Please try again.";
fi;
return 1;
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment