Month: February 2012

Env for scripts interpreter searching

Posted by – February 15, 2012

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter
for a script, when the interpreter may be in different directories on
different systems.  The following example will find the `perl’ inter-
preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl
One limitation of that example is that it assumes the user’s value for
PATH is set to a value which will find the interpreter you want to exe-
cute.  The -P option can be used to make sure a specific list of directo-
ries is used in the search for utility.  Note that the -S option is also
required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That
could be combined with the present value of PATH, to provide more flexi-
bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter     for a script, when the interpreter may be in different directories on     different systems.  The following example will find the `perl’ inter-     preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl     One limitation of that example is that it assumes the user’s value for     PATH is set to a value which will find the interpreter you want to exe-     cute.  The -P option can be used to make sure a specific list of directo-     ries is used in the search for utility.  Note that the -S option is also     required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That     could be combined with the present value of PATH, to provide more flexi-     bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

Env

Posted by – February 15, 2012

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter
for a script, when the interpreter may be in different directories on
different systems.  The following example will find the `perl’ inter-
preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl
One limitation of that example is that it assumes the user’s value for
PATH is set to a value which will find the interpreter you want to exe-
cute.  The -P option can be used to make sure a specific list of directo-
ries is used in the search for utility.  Note that the -S option is also
required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That
could be combined with the present value of PATH, to provide more flexi-
bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter     for a script, when the interpreter may be in different directories on     different systems.  The following example will find the `perl’ inter-     preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl     One limitation of that example is that it assumes the user’s value for     PATH is set to a value which will find the interpreter you want to exe-     cute.  The -P option can be used to make sure a specific list of directo-     ries is used in the search for utility.  Note that the -S option is also     required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That     could be combined with the present value of PATH, to provide more flexi-     bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl