mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-11 14:33:47 -05:00
added cli options functions
This commit is contained in:
16
lib/utils.sh
16
lib/utils.sh
@@ -9,12 +9,12 @@
|
||||
# First we locate this script and populate the $SCRIPTPATH variable
|
||||
# Doing so allows us to source additional files from this utils file.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||
SOURCE="$(readlink "${SOURCE}")"
|
||||
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if ${SOURCE} was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
SOURCEPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCEPATH="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||
|
||||
# Write the list of utility files to be sourced
|
||||
FILES="
|
||||
@@ -26,10 +26,10 @@ FILES="
|
||||
# Source the Utility Files
|
||||
for file in $FILES
|
||||
do
|
||||
if [ -f "$SOURCEPATH/$file" ]; then
|
||||
source "$SOURCEPATH/$file"
|
||||
if [ -f "${SOURCE}PATH/${file}" ]; then
|
||||
source "${SOURCE}PATH/${file}"
|
||||
else
|
||||
e_error "$file does not exist. Exiting"
|
||||
e_error "${file} does not exist. Exiting"
|
||||
Exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user