Skip to main content
10 events
when toggle format what by license comment
Mar 4, 2024 at 12:28 comment added Vilinkameni @JohnMahowald env(1) sets the environment variables, but it will execute the script itself again, creating an endless loop. See unix.stackexchange.com/a/670339/367454
May 13, 2021 at 22:43 comment added FKEinternet The cited source, and consequently this answer, contains a number of errors: The executable specified after the shebang is the interpreter for the rest of the script, and is frequently not bash. As @thomas-nyman points out, the shebang-specified interpreter will be ignored if another shell is called on the command line to interpret the file. If env is used to specify the executable, the user's path is searched to find the program, it is not an absolute path. The default shell is operating system dependent, you cannot assume it will be sh.
Jul 24, 2018 at 22:08 comment added John Mahowald env to find a program in $PATH is a bit of a hack. It doesn't set environment variables like the name implies. $PATH might be a different result for different users. But it helps scripts run without modification on systems which put a reasonable perl interpreter in some odd place.
S Mar 17, 2016 at 17:24 history edited MelBurslan CC BY-SA 3.0
added 1 character in body
Mar 17, 2016 at 17:20 review Suggested edits
S Mar 17, 2016 at 17:24
Aug 22, 2013 at 8:23 comment added sambler @polemon less of which is preferred and more on which paths vary. The basic shells are in the same path on all systems. Up to date versions of perl and python can be installed in different locations on different systems so using env allows the same shebang to always work, which is why env is used more with perl and python scripts than shell scripts.
Aug 21, 2013 at 10:22 comment added polemon @sambler speaking of env, which should be actually prefered? Python and Perl often use env, while on shellscripts, this is often omitted and shebang points to the shell in question.
Aug 21, 2013 at 7:31 comment added sambler Also note that this isn't limited to shell scripts. All text based script files use this. eg #!/usr/bin/perl #!/usr/local/bin/python #!/usr/local/bin/ruby Another common shebang entry used to support multiple systems is to use env to locate the interpreter you want to use, like #!/usr/bin/env perl #!/usr/bin/env python
Aug 21, 2013 at 6:37 comment added Simon Richter To elaborate, the kernel only knows how to execute statically linked binaries and where to find interpreter information for others (a special field in the binary, or the shebang line). Typically executing a shell script means following the shebang line to the shell, and then following the DT_INTERP field in the shell binary to the dynamic linker.
Aug 21, 2013 at 4:12 history answered vfbsilva CC BY-SA 3.0