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?

4 Answers 4


. 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] $ cd /usr/bin
[/usr/bin] $ /tmp/test.sh

I agree with Michael, but one place where it may matter is $0 parameter.

I've seen scripts that investigate the name of $0 and do different things based upon what symbolic name is used.

  • 1
    Not just scripts but complicated programs. Look at busybox for an example of a complicated program that matters what you call it as. Sep 8, 2010 at 16:56

The . 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 realpath. Although dirname returns . if its arg has no directory part, in this example realpath will already have turned the arg into an absolute path.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .