Questions tagged [env]

22 questions
74
votes
3 answers

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 /usr/bin/env: ruby --verbose: No such file or…
rampion
  • 1,589
  • 1
  • 10
  • 14
45
votes
2 answers

what is `env ` doing?

What is the command env ls -al doing? I had a Linux test and there was question: "How to run command directly, but not its alias?" I knew that there exists solution like prefixing command with some special symbol, but I forgot it. Now I know that it…
ALZ
  • 921
  • 2
  • 10
  • 13
33
votes
6 answers

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 kind of believe that it's related with the -f. But how…
Cheng
  • 6,531
  • 11
  • 40
  • 42
20
votes
1 answer

Is there a difference between prepending a name-value-pair to a command and using env in bash?

Let's say I invoke A=B command and env A=B command in bash. Is there any situation where there might be a difference between both invokations?
Kalle Richter
  • 2,100
  • 4
  • 20
  • 37
17
votes
5 answers

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.
balki
  • 4,327
  • 5
  • 30
  • 44
12
votes
4 answers

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 quotes and works with stdin. The GNU Awk manual has…
user2672807
  • 1
  • 1
  • 6
10
votes
2 answers

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 multiple versions of Ruby installed, you may want to…
sffc
  • 231
  • 2
  • 7
10
votes
4 answers

Setting environment vars containing space with env

I'm trying to use env to set environment variables (read from another source, say for example a file) for a subprocess. Essentially, I am attempting the following: env VALUE=thisisatest ./somescript.sh If, for example, somescript.sh was: echo…
Bailey Parker
  • 310
  • 1
  • 2
  • 11
9
votes
2 answers

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 see the source, is there an easy way to get them…
dr jerry
  • 319
  • 2
  • 4
  • 8
9
votes
1 answer

Is there any guarantee that /usr/bin/env will exist?

Often I will see scripts begin with a shebang line that uses #!/usr/bin/env interpreter_name for whatever interpreter, with the rationale that different systems might have the interpreter that they need in order to run installed in different places.…
6
votes
2 answers

/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 - with -- causes /usr/bin/env to print a similar…
kjo
  • 14,779
  • 25
  • 69
  • 109
5
votes
2 answers

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 & $ pgrep bar.sh 21202 The process started by env bash shows…
terdon
  • 234,489
  • 66
  • 447
  • 667
5
votes
2 answers

Introduction of env --null

I have tried to extract environment variables in a Python process with help of env --null, which works even for environment variables containing newline character. But on some machines I have received an error: > env -0 env: invalid option -- '0' >…
Peter Petrik
  • 153
  • 6
4
votes
3 answers

Upstart - load bashrc variable

I'm wondering how to load bashrc variables in an upstart script and run (node.js in that case server). What is the best way to do it? I tried this: exec sudo -u someuser $NODE_PATH $FULL_PATH/$FILE_NAME >> /var/log/$PROGRAM_NAME.sys.log 2>&1 and…
user1760395
  • 43
  • 1
  • 4
4
votes
0 answers

Reading from /etc/environment with sudo

Using Ubuntu 14.04 LTS, I'm having a problem trying to read environment variables from /etc/environment when using sudo env. Basically, they are not being displayed. When I do just env, these variables appear like it should. In my other server,…
limc
  • 153
  • 6
1
2