The env tag has no wiki summary.
4
votes
3answers
90 views
How to start a script with clean environment?
I tried the following but it doesn't seem to work:
$ cat script.sh
#!/bin/env -i /bin/sh
/bin/env
$ script.sh
/bin/env: invalid option -- ' '
Try `/bin/env --help' for more information.
4
votes
2answers
54 views
Distributing a script: Should I use /bin/gawk or /usr/bin/gawk for shebang?
Is gawk in /bin or /usr/bin usually? I would go with #!/usr/bin/env gawk but then I can't use arguments. Right now I'm using #!/bin/gawk -f. The script is very long and contains a lot of single ...
3
votes
2answers
117 views
Why can't pgrep find scripts started via env?
For example:
$ cat foo.sh
#!/usr/bin/env bash
while true; do sleep 1 ; done
$ ./foo.sh &
$ pgrep foo.sh
$
Contrast with:
$ cat bar.sh
#!/bin/bash
while true; do sleep 1 ; done
$ ./bar.sh &
...
2
votes
2answers
842 views
/usr/bin/env: zsh -: No such file or directory
I get the error
/usr/bin/env: zsh -: No such file or directory
...when I run an executable zsh script that starts with the following shebang line:
#!/usr/bin/env zsh -
Also, FWIW, replacing - ...
2
votes
1answer
87 views
How to get functions propagated to subshell?
Solaris / sh
I have a few functions defined in a file which gets loaded via
. ./some_file.sh
When I start a subshell with
sh
All my function definitions are lost but when I do
env
I do ...
10
votes
2answers
486 views
Shebang line with `#!/usr/bin/env command --argument` fails on Linux
I've got a simple script:
#!/usr/bin/env ruby --verbose
# script.rb
puts "hi"
On my OSX box, it runs fine:
osx% ./script.rb
hi
However, on my linux box, it throws an error
linux% ./script.rb
...
4
votes
2answers
463 views
How do you specify alternative script interpreters (shebangs)?
In an executable file, you specify the environment using a shebang:
#!/usr/bin/env ruby
# ruby code here
But what if you want to specify multiple possible environments? For example, if you have ...
43
votes
5answers
6k views
Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?
I notice that some scripts which I have acquired from others have the shebang #!/path/to/NAME while others (using the same tool, NAME) have the shebang #!/usr/bin/env NAME.
Both seem to work ...
1
vote
3answers
524 views
chmod - change permissions on a file
I have a Python virtualenv, and the Python executable is located in the /bin directory. In this virtualenv I'll have to execute some unsafe code, that can damage my system. I tried to chmod a-r on the ...
5
votes
3answers
2k views
The way to use `/usr/bin/env sed -f ` in shebang?
Typing /usr/bin/env sed -f in terminal works.
But if use it as a shebang,
#!/usr/bin/env sed -f
s/a/b/
The script will be fail to execute:
/usr/bin/env: sed -f: No such file or directory
I ...