Let's say /A/B/c.sh is symbolic linked to /X/Y/c.sh.
- If c.sh has the command "./SOMETHING", '.' means /A/B/ or /X/Y/?
- How about the hard link?
. is actually the current working directory in either case; it has nothing to do with the directory holding the script:
[/tmp] $ echo "realpath ." > test.sh && chmod +x test.sh [/tmp] $ /tmp/test.sh /tmp [/tmp] $ cd /usr/bin [/usr/bin] $ /tmp/test.sh /usr/bin
I agree with Michael, but one place where it may matter is
I've seen scripts that investigate the name of
$0 and do different things based upon what symbolic name is used.
. in this case means the current working directly; the links' paths are irrelevant. Referencing the file for execution or editing is essentially the same regardless of the type of link, even though there are several differences between them.
Although this isn't what you asked, it may be what you're looking for ...
You can use
"$0" as a way to locate sub-scripts that are located in the same directory as the main script.
MYPATH="$(realpath "$0")" MYDIR="$(dirname "$MYPATH")" "$MYDIR/otherscript" ...
Since the main script is symlinked you need to dereference
$0 first, using
. if its arg has no directory part, in this example
realpath will already have turned the arg into an absolute path.