When you look at a file reference, it’s easy to tell if it’s an absolute or relative reference. You look at the first character. If it’s a slash (/), it’s absolute. If it’s a tilde (~), it’s also absolute because it will resolve to a file within someone’s home directory. And, if it’s anything else, it’s relative.

Making the same decision within a script depends on that same kind of analysis. You just have to look at the first character in the argument string to determine whether the file argument provided refers to a file that is relative to the file system location from which the script is run or is an absolute file reference.

To nail down this determination, you can use some fairly simple logic. In the mini script below, we focus on the first character of the first argument to distinguish absolute from relative file references.

To read this article in full or to leave a comment, please click here

Source: COMPUTER WORLD