Jordan Jordan - 1 year ago 112
Linux Question

Determine if relative or absolute path in shell program

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/dir/dir2/program #absolute
/home/User/dir/dir2/program #absolute

This are my test cases. How exactly could I go about doing this in a shell program?

Answer Source
if [[ "$0" = /* ]]
   : # Absolute path
   : # Relative path
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download