0

In Linux adding #!/bin/bash is telling the the executable to execute with bash.

I was wondering, why is this specified in full path? I would expect that since bin is in a path specified in PATH it would find it just by adding #!bash

This is not really an inconvenience, just curious. Thanks

Return-1
  • 141

1 Answers1

1

The way #! works is that it must be followed by the full pathname of the interpreter. If you want to search $PATH the commonly used construction is #!/usr/bin/env <interpreter>, for example

#!/usr/bin/env perl

will look for perl in $PATH. For more information for why this works see the manual page for env and the nice discussion under "How does /usr/bin/env know which program to use?" on this forum.

AlexP
  • 10,455