Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?
share|improve this question
add comment

4 Answers

up vote 10 down vote accepted

. 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
share|improve this answer
add comment

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.

share|improve this answer
1  
Not just scripts but complicated programs. Look at busybox for an example of a complicated program that matters what you call it as. –  xenoterracide Sep 8 '10 at 16:56
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.