1

Could someone please explain this to me? I'm having trouble understanding how this is set up and why it behaves the way it does.

I wanted to see where zsh is actually installed on a machine that I use. So I used ls to find where the symlink points.

$ ls -l /bin/zsh
lrwxrwxrwx   1 root     root          14 Dec  1  2011 /bin/zsh -> ../sfw/bin/zsh*

When I saw this, I thought, "Okay, the symlink uses a relative path. No big deal."

But if I then try to cd directly to what should be where the relative path points, I get this:

$ cd /bin/sfw/bin
cd: no such file or directory: /bin/sfw/bin

However, if I specifically type this

$ cd ../sfw/bin

when /bin is the working directory, then it works. And then I also get this:

$ pwd
/usr/sfw/bin

What is going on here?

2

/bin is probably a symlink to /usr/bin on your system. If that were true then:

/bin/../sfw/bin/zsh

would actually be the same as

/usr/bin/../sfw/bin/zsh

which reduces to

/usr/sfw/bin/zsh

which is where zsh actually lives. Note that what you tried, which was

/bin/sfw/bin

does not correspond to any path that you actually could see on the system. The correct way to resolve a relative path (../sfw/bin/zsh) given the absolute path path that forms the base for that relative path (/bin) is to concatenate them together as /bin/ + ../sfw/bin/zsh/bin/../sfw/bin/zsh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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