Last active
August 29, 2015 14:17
-
-
Save randomcamel/71a581bad6d66f38de6e to your computer and use it in GitHub Desktop.
/usr/bin/env called from shebang hangs with an invocation that works from the command line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| root@server-12-ubuntu-1404:~# /usr/bin/env PATH=/opt/chef-server/embedded/bin ruby -e 'puts ENV["PATH"]' | |
| /opt/chef-server/embedded/bin | |
| root@server-12-ubuntu-1404:~# cat foo.rb | |
| #!/usr/bin/env PATH=/opt/chef-server/embedded/bin ruby | |
| puts ENV["PATH"] | |
| root@server-12-ubuntu-1404:~# ./foo.rb | |
| ^C | |
| root@server-12-ubuntu-1404:~# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| execve("./foo.rb", ["./foo.rb"], [/* 25 vars */]) = 0 | |
| brk(0) = 0x1680000 | |
| access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) | |
| mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fabb8cab000 | |
| access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) | |
| open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 | |
| fstat(3, {st_mode=S_IFREG|0644, st_size=20641, ...}) = 0 | |
| mmap(NULL, 20641, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fabb8ca5000 | |
| close(3) = 0 | |
| access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) | |
| open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 | |
| read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\37\2\0\0\0\0\0"..., 832) = 832 | |
| fstat(3, {st_mode=S_IFREG|0755, st_size=1845024, ...}) = 0 | |
| mmap(NULL, 3953344, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fabb86c5000 | |
| mprotect(0x7fabb8880000, 2097152, PROT_NONE) = 0 | |
| mmap(0x7fabb8a80000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bb000) = 0x7fabb8a80000 | |
| mmap(0x7fabb8a86000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fabb8a86000 | |
| close(3) = 0 | |
| mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fabb8ca4000 | |
| mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fabb8ca2000 | |
| arch_prctl(ARCH_SET_FS, 0x7fabb8ca2740) = 0 | |
| mprotect(0x7fabb8a80000, 16384, PROT_READ) = 0 | |
| mprotect(0x605000, 4096, PROT_READ) = 0 | |
| mprotect(0x7fabb8cad000, 4096, PROT_READ) = 0 | |
| munmap(0x7fabb8ca5000, 20641) = 0 | |
| brk(0) = 0x1680000 | |
| brk(0x16a1000) = 0x16a1000 | |
| open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 | |
| fstat(3, {st_mode=S_IFREG|0644, st_size=2919792, ...}) = 0 | |
| mmap(NULL, 2919792, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fabb83fc000 | |
| close(3) = 0 | |
| # ----------- repeats ----------- | |
| execve("./foo.rb", ["./foo.rb"], [/* 25 vars */]) = 0 | |
| brk(0) = 0x1619000 | |
| access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) | |
| [...] |
Author
Author
An analogous shebang works fine on OS X 10.9.
Author
Looks like computers are terrible: http://stackoverflow.com/a/10217307
tl;dr /usr/bin/env kinda doesn't really work right on Linux.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same effect if the shebang line is
#!/usr/bin/env PATH=/opt/chef-server/embedded/bin ruby -e 'puts ENV["PATH"]'The shebang line limit is defined in
/usr/include/linux/binfmts.h:And I'm only at 53.