As stated in the title, I need to determine when a program is ran if the path is relative or absolute:
./program #relative
dir/dir2/program #relative
~User/d
case "$directory" in
/*)
echo "absolute"
;;
*)
echo "relative"
;;
esac
if [ ${path:0:1} == / ]
then
echo Absolute path
else
echo Non-absolute path
fi
A general solution for any $path
, rather than just $0
[ "$path" != "${path#/}" ] && echo "absolute" || echo "relative"
if [[ "$0" = /* ]]
then
: # Absolute path
else
: # Relative path
fi