4

I have an executable script test under the full path /home/sawa/foo/bar/test. The directory /home/sawa/foo/bar is within $PATH, and has priority over the default ones including /usr/bin. When I do

`which test`

to see whether this command is correctly recognized, it returns

/home/sawa/foo/bar//test

with the double slash //. I know that there is a built in command with the same name test, and when I remove mine, this one under /usr/bin/test is returned by which, so I think it's interfering in some way.

  1. What does this double slash mean here, and why is it appearing here?
  2. My executable test does not seem to work correctly. Why is that?
7

I would guess that you have /home/sawa/foo/bar/ on your path - i.e. a path with a trailing slash.

which is iterating over each element of $PATH and appending /argv[1] and checking for the existence of that file. That causes a double-slash - one from the $PATH part, and one from /argv[1].

A double-slash is no problem. It is collapsed to a single slash by the kernel. Only at the beginning of a path may a double-slash have special meaning, and not always then.

As for test not working, ensure you are not using the shell built-in when calling test. You usually do this by using a full path, but with bash you can also use enable -n test to disable the built-in test command.

  • Thanks. That's the perfect answer that I wanted. It helps. – sawa May 3 '11 at 15:18
3

Most likely it doesn't work for you because the shell builtin is getting executed with priority over any executable. You should not knowingly create a name conflict like this, behavior will be inconsistent across environments. The system binary test is only there for the use of shells that don't have a builtin version.

If you want alternate functionality, you should name your script something else.

  • 1
    That advice given, I don't actually know what // represents here so it will be interesting to hear from somebody who does :) – Caleb May 3 '11 at 8:58

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.