Smarter way to get absolute location

This commit is contained in:
cspark 2024-03-18 11:07:36 +00:00
parent 7a4818592f
commit f4ed15669c
3 changed files with 3 additions and 21 deletions

View File

@ -11,13 +11,7 @@ USBKEYVAR=/dev/disk/by-uuid/{{ usbkey_uuid }}
USBKEYSLOCATION={{ usbkey_keysdir }}
# Figure out if path given is relative or absolute, assign variables accordingly
if [[ "$(echo $1 | cut -c 1)" == "/" ]]; then
# Absolute
ABSOLUTELOCATION=$1
else
# Relative
ABSOLUTELOCATION="$(pwd)/$1"
fi
ABSOLUTELOCATION=$(realpath $1)
# Probably cleaner to do this in awk or the like but good enough!
# FILEPARENTDIR="$(echo $ABSOLUTELOCATION | cut -d / --fields=$(echo $ABSOLUTELOCATION | grep -o / | wc -l))"
FILENAME="$(echo $ABSOLUTELOCATION | cut -d / --fields=$(($(echo $ABSOLUTELOCATION | grep -o / | wc -l) + 1))-)"

View File

@ -11,13 +11,7 @@ USBKEYVAR=/dev/disk/by-uuid/{{ usbkey_uuid }}
USBKEYSLOCATION={{ usbkey_keysdir }}
# Figure out if path given is relative or absolute, assign variables accordingly
if [[ "$(echo $1 | cut -c 1)" == "/" ]]; then
# Absolute
ABSOLUTELOCATION=$1
else
# Relative
ABSOLUTELOCATION="$(pwd)/$1"
fi
ABSOLUTELOCATION=$(realpath $1)
# Probably cleaner to do this in awk or the like but good enough!
FILEPARENTDIR="$(echo $ABSOLUTELOCATION | cut -d / --fields=$(echo $ABSOLUTELOCATION | grep -o / | wc -l))"
FILENAME="$(echo $ABSOLUTELOCATION | cut -d / --fields=$(($(echo $ABSOLUTELOCATION | grep -o / | wc -l) + 1))-)"

View File

@ -11,13 +11,7 @@ USBKEYVAR=/dev/disk/by-uuid/{{ usbkey_uuid }}
USBKEYSLOCATION={{ usbkey_keysdir }}
# Figure out if path given is relative or absolute, assign variables accordingly
if [[ "$(echo $1 | cut -c 1)" == "/" ]]; then
# Absolute
ABSOLUTELOCATION=$1
else
# Relative
ABSOLUTELOCATION="$(pwd)/$1"
fi
ABSOLUTELOCATION=$(realpath $1)
# Probably cleaner to do this in awk or the like but good enough!
# FILEPARENTDIR="$(echo $ABSOLUTELOCATION | cut -d / --fields=$(echo $ABSOLUTELOCATION | grep -o / | wc -l))"
FILENAME="$(echo $ABSOLUTELOCATION | cut -d / --fields=$(($(echo $ABSOLUTELOCATION | grep -o / | wc -l) + 1))-)"