Sponsored Content
Top Forums Shell Programming and Scripting Discussion: use "/usr/bin/env" or not Post 302973164 by Don Cragun on Sunday 15th of May 2016 01:32:23 PM
Old 05-15-2016
On many systems, #!/usr/bin/env utility will work for many common cases.

On systems that support multiple programming environments (like Solaris systems that use $PATH to choose between SVID3, XGP3, XPG4, XPG5, XPG6, old BSD, etc. environments), something like #!/usr/bin/env cmd where cmd is sh, awk, grep, sed, or any other utility that has different versions depending on the environment chosen) might or might not give you what you want depending on how PATH is set by the user invoking your script.

Since I worked at Sun for more than twenty years, I almost never use #!/usr/bin/env. And, I would never use that in any script that I would expect to ever be run on a Solaris system to get access to any utility that uses internationalized regular expressions.

Note also that I frequently see people posting scripts that use:
Code:
#!/usr/bin/env utility arg1 arg2 ...

or:
Code:
#! /usr/bin/env utility arg1 arg2 ...

but on some systems (at least in the late 1980's and early 1990's when the first version of the POSIX utilities standard was being developed) everything following the #! is treated as the name of the interpreter to be invoked. On those systems (if any still exist):
Code:
#!/usr/bin/env bash

will fail unless there is a utility named env<space>bash in /usr/bin. And, I'm pretty sure that there are still systems that will accept an interpreter name and one argument to it (as in the above invocation of bash), but won't accept more than one argument, such as in:
Code:
#!/usr/bin/env bash -xv

 

10 More Discussions You Might Find Interesting

1. Programming

Differece between "env" and "set" command

Hi, Please clarify what is the difference between "env" and "set" command. I guess set will display the system variables and user defined variables. Thanks Sweta (1 Reply)
Discussion started by: sweta
1 Replies

2. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

3. UNIX for Dummies Questions & Answers

#!/bin/sh script fails at StringA | tr "[x]" "[y]"

I need to take a string (stringA) check it for spaces and replace any spaces found with an equal (=) sign. This is not working. There are spaces between each component: $StringA | tr "" "" The error returned is: test: Specify a parameter with this command Can you help? (3 Replies)
Discussion started by: by_tg
3 Replies

4. Shell Programming and Scripting

What does "#@$-s /usr/bin/ksh -x " mean?

I am using ksh.. Whenever we write a shell script the first statement would be #! /bin/ksh. But instead of that I came to find "#@$-q large" in the first line and"#@$-s /usr/bin/ksh -x " in the second line. what does it mean? Give your comments..... Thanks sabeer (4 Replies)
Discussion started by: sabeeralict
4 Replies

5. Solaris

difference between "root" and "usr" packages

Hi, could someone pls enlighten me on the difference between the "root" package and "usr" package? Like in this example: pkginfo -l SUNWGtku | grep -i desc DESC: GTK - The GIMP Toolkit (Usr) and pkginfo -l SUNWGtkr | grep -i desc DESC: GTK - The GIMP Toolkit (Root)... (6 Replies)
Discussion started by: masloff
6 Replies

6. Solaris

Execution problem with "/usr/dt/bin/sdtdbcache

On a SunOS Solaris 5.5.1 workstation, the /usr/dt/bin/sdtdbcache –init command lasts more than 20 minutes. This command is executed by the /usr/dt/bin/Xsession script during an user connection. Please refrain from using subjects like "HELP ME!..." to get more/faster attention and also please do... (1 Reply)
Discussion started by: ricadom
1 Replies

7. UNIX for Dummies Questions & Answers

Difference between "/bin/bash" & "/bin/sh"

what if the difference between #!/bin/sh and #!/bin/bash I wrote a script with the second heading now when i change my heading to the first one ...the script is not executing well....im not getting the required output....any solution to this problem...or do i have to start the... (3 Replies)
Discussion started by: xerox
3 Replies

8. Solaris

The slices "usr", "opt", "tmp" disappeared!!! Help please.

The system don't boot. on the screen appears following: press enter to maintenance (or type CTRL-D to continue)...I checked with format command. ... the slices "0-root","1-swap","2-backup" exist. ...the slises "3-var","6-usr" -unassigned. :( (16 Replies)
Discussion started by: wolfgang
16 Replies

9. Shell Programming and Scripting

If cmd in in "A/user/bin A/bin A/user/sbin" but not "B/user/bin B/bin B/user/sbin" directory print t

there are two directories A and B if cmd in in "A/user/bin A/bin A/user/sbin" but not "B/user/bin B/bin B/user/sbin" directory print them (1 Reply)
Discussion started by: yanglei_fage
1 Replies

10. Shell Programming and Scripting

Mindboggling difference between using "tee" and "/usr/bin/tee" in bash

I'm on Ubuntu 14.04 and I manually updated my coreutils so that "tee" is now on version 8.27 I was running a script using bash where there is some write to pipe error at some point causing the tee command to exit abruptly while the script continues to run. The newer version of tee seems to prevent... (2 Replies)
Discussion started by: stompadon
2 Replies
All times are GMT -4. The time now is 03:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy