I am writing a generic script that can get passed both absolute and relative (to the current working dir) paths to existing files.
I need a fail-safe way to turn all those passed paths into absolute paths because I need to pass the paths to the "open" command, which in won't pass the current directory to the launched app.
One idea I had is to check if the path starts with a "/", and if not, then I'd prepend the current working dir's path to it.
However, I wonder if there's a smarter solution to this. Also, as I'm quite inexperienced with shell scripting and related tools, I don't even know how to test for a variable's value to start with "/". I'm looking for a portable solution to run on multiple Mac, so installing extra tools or configuration would be less than ideal.
Can someone suggest a standard script using only shipping tools that takes a variable (let's call it $path) and turns it into a absolute path if it's not already absolute?