Created
January 2, 2012 18:11
-
-
Save dperezrada/1551578 to your computer and use it in GitHub Desktop.
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
# 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