#!/usr/bin/env foo #!vs /usr/bin/foo [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
Why is it better to use â#!/usr/bin/env NAMEâ instead of â#!/path/to/NAMEâ as my shebang?
9 answers
Which of the above forms is "better" for running bash, python etc. scripts? Why can't I just do #!$(which foo)
? Is it neccecery to specify full path to env
? I gather from this answer, that the path /usr/bin/env
is set in stone for all *nix-es, much more than /usr/bin/python3
for example. Is that so?
scripting path shebang
marked as duplicate by muru, Hunter.S.Thompson, peterh, jimmij, Raphael Ahrens Nov 19 '17 at 15:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
Why is it better to use â#!/usr/bin/env NAMEâ instead of â#!/path/to/NAMEâ as my shebang?
9 answers
Which of the above forms is "better" for running bash, python etc. scripts? Why can't I just do #!$(which foo)
? Is it neccecery to specify full path to env
? I gather from this answer, that the path /usr/bin/env
is set in stone for all *nix-es, much more than /usr/bin/python3
for example. Is that so?
scripting path shebang
marked as duplicate by muru, Hunter.S.Thompson, peterh, jimmij, Raphael Ahrens Nov 19 '17 at 15:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
Why is it better to use â#!/usr/bin/env NAMEâ instead of â#!/path/to/NAMEâ as my shebang?
9 answers
Which of the above forms is "better" for running bash, python etc. scripts? Why can't I just do #!$(which foo)
? Is it neccecery to specify full path to env
? I gather from this answer, that the path /usr/bin/env
is set in stone for all *nix-es, much more than /usr/bin/python3
for example. Is that so?
scripting path shebang
This question already has an answer here:
Why is it better to use â#!/usr/bin/env NAMEâ instead of â#!/path/to/NAMEâ as my shebang?
9 answers
Which of the above forms is "better" for running bash, python etc. scripts? Why can't I just do #!$(which foo)
? Is it neccecery to specify full path to env
? I gather from this answer, that the path /usr/bin/env
is set in stone for all *nix-es, much more than /usr/bin/python3
for example. Is that so?
This question already has an answer here:
Why is it better to use â#!/usr/bin/env NAMEâ instead of â#!/path/to/NAMEâ as my shebang?
9 answers
scripting path shebang
edited Nov 19 '17 at 11:00
Jeff Schaller
32.1k849109
32.1k849109
asked Nov 19 '17 at 10:49
Vorac
94621732
94621732
marked as duplicate by muru, Hunter.S.Thompson, peterh, jimmij, Raphael Ahrens Nov 19 '17 at 15:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Hunter.S.Thompson, peterh, jimmij, Raphael Ahrens Nov 19 '17 at 15:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
You canâÂÂt just write #!$(which foo)
because that line is interpreted by the kernel, which does not understand complex syntaxes like $()
.
The kernel does not search for the command in the PATH
environment variable. ThatâÂÂs why you have to specify the full path to the command.
The use of /usr/bin/env
is a clever hack used to search the command in the PATH
. Even if there is a /usr/bin/python3
program, you may for example have installed a more recent version of Python in a different path, for example in you home directory.
Ahaa, so$()
is a shell feature. As well as searching the path, consequently I can't just write#!python3
. What about the cross-platform issue. Do we get/usr/bin/env
on MacOS? FreeBSD? QNX?
â Vorac
Nov 19 '17 at 11:03
Searching thePATH
is not exactly a shell feature; it is alibc
feature. ThatâÂÂs only a guess, but/usr/bin/env
might be required by the POSIX standard.
â user2233709
Nov 19 '17 at 11:13
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You canâÂÂt just write #!$(which foo)
because that line is interpreted by the kernel, which does not understand complex syntaxes like $()
.
The kernel does not search for the command in the PATH
environment variable. ThatâÂÂs why you have to specify the full path to the command.
The use of /usr/bin/env
is a clever hack used to search the command in the PATH
. Even if there is a /usr/bin/python3
program, you may for example have installed a more recent version of Python in a different path, for example in you home directory.
Ahaa, so$()
is a shell feature. As well as searching the path, consequently I can't just write#!python3
. What about the cross-platform issue. Do we get/usr/bin/env
on MacOS? FreeBSD? QNX?
â Vorac
Nov 19 '17 at 11:03
Searching thePATH
is not exactly a shell feature; it is alibc
feature. ThatâÂÂs only a guess, but/usr/bin/env
might be required by the POSIX standard.
â user2233709
Nov 19 '17 at 11:13
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
add a comment |Â
up vote
1
down vote
You canâÂÂt just write #!$(which foo)
because that line is interpreted by the kernel, which does not understand complex syntaxes like $()
.
The kernel does not search for the command in the PATH
environment variable. ThatâÂÂs why you have to specify the full path to the command.
The use of /usr/bin/env
is a clever hack used to search the command in the PATH
. Even if there is a /usr/bin/python3
program, you may for example have installed a more recent version of Python in a different path, for example in you home directory.
Ahaa, so$()
is a shell feature. As well as searching the path, consequently I can't just write#!python3
. What about the cross-platform issue. Do we get/usr/bin/env
on MacOS? FreeBSD? QNX?
â Vorac
Nov 19 '17 at 11:03
Searching thePATH
is not exactly a shell feature; it is alibc
feature. ThatâÂÂs only a guess, but/usr/bin/env
might be required by the POSIX standard.
â user2233709
Nov 19 '17 at 11:13
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You canâÂÂt just write #!$(which foo)
because that line is interpreted by the kernel, which does not understand complex syntaxes like $()
.
The kernel does not search for the command in the PATH
environment variable. ThatâÂÂs why you have to specify the full path to the command.
The use of /usr/bin/env
is a clever hack used to search the command in the PATH
. Even if there is a /usr/bin/python3
program, you may for example have installed a more recent version of Python in a different path, for example in you home directory.
You canâÂÂt just write #!$(which foo)
because that line is interpreted by the kernel, which does not understand complex syntaxes like $()
.
The kernel does not search for the command in the PATH
environment variable. ThatâÂÂs why you have to specify the full path to the command.
The use of /usr/bin/env
is a clever hack used to search the command in the PATH
. Even if there is a /usr/bin/python3
program, you may for example have installed a more recent version of Python in a different path, for example in you home directory.
answered Nov 19 '17 at 10:56
user2233709
603310
603310
Ahaa, so$()
is a shell feature. As well as searching the path, consequently I can't just write#!python3
. What about the cross-platform issue. Do we get/usr/bin/env
on MacOS? FreeBSD? QNX?
â Vorac
Nov 19 '17 at 11:03
Searching thePATH
is not exactly a shell feature; it is alibc
feature. ThatâÂÂs only a guess, but/usr/bin/env
might be required by the POSIX standard.
â user2233709
Nov 19 '17 at 11:13
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
add a comment |Â
Ahaa, so$()
is a shell feature. As well as searching the path, consequently I can't just write#!python3
. What about the cross-platform issue. Do we get/usr/bin/env
on MacOS? FreeBSD? QNX?
â Vorac
Nov 19 '17 at 11:03
Searching thePATH
is not exactly a shell feature; it is alibc
feature. ThatâÂÂs only a guess, but/usr/bin/env
might be required by the POSIX standard.
â user2233709
Nov 19 '17 at 11:13
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
Ahaa, so
$()
is a shell feature. As well as searching the path, consequently I can't just write #!python3
. What about the cross-platform issue. Do we get /usr/bin/env
on MacOS? FreeBSD? QNX?â Vorac
Nov 19 '17 at 11:03
Ahaa, so
$()
is a shell feature. As well as searching the path, consequently I can't just write #!python3
. What about the cross-platform issue. Do we get /usr/bin/env
on MacOS? FreeBSD? QNX?â Vorac
Nov 19 '17 at 11:03
Searching the
PATH
is not exactly a shell feature; it is a libc
feature. ThatâÂÂs only a guess, but /usr/bin/env
might be required by the POSIX standard.â user2233709
Nov 19 '17 at 11:13
Searching the
PATH
is not exactly a shell feature; it is a libc
feature. ThatâÂÂs only a guess, but /usr/bin/env
might be required by the POSIX standard.â user2233709
Nov 19 '17 at 11:13
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
You can't use #!$(which foo) because shell expansion does not occur for comments... as in #! (a comment)... This is by specific design. There is no "better" or "best" way to set your interpreter. I tend to use #!/usr/bin/env perl + #!/usr/bin/env ffmpeg, because I build these nightly, against latest source. So in general, you'll use /usr/bin/env when you have multiple copies of a program in your $PATH + you'd like to take the highest precedence version (one appearing first in your $PATH variable).
â David Favor
Nov 19 '17 at 13:01
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@DavidFavor It does not matter that itâÂÂs a comment, it matters that it is a special kernel feature.
â user2233709
Nov 19 '17 at 13:08
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
@MarkPlotnick Are you sure it is a feature of the shell? I just gave it a try, and could also run that shell script through /usr/bin/envâ¦
â user2233709
Nov 19 '17 at 14:23
add a comment |Â