Skip to content

Instantly share code, notes, and snippets.

@dperezrada
Created January 2, 2012 18:11
Show Gist options
  • Save dperezrada/1551578 to your computer and use it in GitHub Desktop.
Save dperezrada/1551578 to your computer and use it in GitHub Desktop.
# Get some path and absolutes paths
PATH_BEFORE_SCRIPT=`pwd`;
SCRIPT_NAME=`basename $0`;
SCRIPT_DIRNAME=`dirname $0`;
cd $SCRIPT_DIRNAME;
SCRIPT_ABSOLUTE_DIRNAME=`pwd`;
# We expect one parameter
if [[ "$#" -ne 1 ]]; then
echo "Usage: script_with_target_dir.sh <target_dir>" >&2;
exit 1;
fi
# Check if target directory exists
TARGET_DIR=$1;
if [[ ! -d "$TARGET_DIR" ]]; then
echo "target_dir doesn't exists" >&2;
exit 1;
fi
# Print all variables
echo "PATH_BEFORE_SCRIPT: $PATH_BEFORE_SCRIPT";
echo "SCRIPT_NAME: $SCRIPT_NAME";
echo "SCRIPT_DIRNAME: $SCRIPT_DIRNAME";
echo "SCRIPT_ABSOLUTE_DIRNAME: $SCRIPT_ABSOLUTE_DIRNAME";
echo "TARGET_DIR: $TARGET_DIR";
# Return to the path before script
cd $PATH_BEFORE_SCRIPT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment