4

The test condition [ is a program, which is residing on debian based distributions in /usr/bin/[. I would like to know if the other condition tester [[ is also a program?

The reason why I am asking: I granted sudo rights to a certain user to let him trigger a shell script. As for security reasons I'm adding the full path to each program (echo to /bin/echo and [ to /usr/bin/[) used in that script, so that the user could not change his PATH to use his own programs. Now I'm wondering if I have to change [[, too.

3
  • 1
    [[ is a keyword. Related: askubuntu.com/a/590335
    – jesse_b
    May 9 '18 at 20:30
  • You say: "I granted sudo rights to a certain user to let him trigger a shell script. "... So shouldn't you only add the path to that shell script to sudoers instead???
    – filbranden
    May 9 '18 at 21:00
  • Note that [ is a builltin command in bash. Presumably it was added to the shell for performance. May 9 '18 at 21:50
5

man bash

RESERVED WORDS
Reserved words are words that have a special meaning to the shell. The following words are recognized as reserved when unquoted and either the first word of a simple command (see SHELL GRAMMAR below) or the third word of a case or for command:

! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]

So [[ is a reserved word and thus cannot be an external command. There might be such a file, though, but it would have to be called with the full path or with quotes.

And even if there was such an external command then it would not work the same way because [[ as part of the shell grammar changes the parsing rules until the next ]]. External commands cannot do that.

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.