workaround: add -S

#! /usr/bin/env -S A=B python
import os; print(os.environ["A"])


why?

shebangs have the limitation (or feature)
that you can pass only one argument

so

#! /usr/bin/env A=B python

is parsed as

argv[0] = "/usr/bin/env"
argv[1] = "A=B python"


you can see this with

#! /usr/bin/printf A=B '(%s) ' 1 2 3 4

which prints

A=B '(./test.sh) ' 1 2 3 4

and

#! /usr/bin/env -S printf '(%s) ' 1 2 3 4

prints

(1) (2) (3) (4) (./test.sh)



now the question is,
why does `argv[1] = "A=B python"` lead to infinite recursion?

expected result:

/usr/bin/env: ‘A=B python’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

just like

#! /usr/bin/env hello world

throws

/usr/bin/env: ‘hello world’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1421760

Title:
  /usr/bin/env hangs when a variable is set

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1421760/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to