Is it correct to use /bin/sh in the hashbang if the Bourne shell isn't available in a distribution?
Generally, shell scripts contain the following comment at the first line of the script file: #!/bin/sh
. According to the researches that I made, this is called "hash bang" and it is conventional comment. This comment informs Unix that this file is executed by the Bourne Shell under the directory /bin
.
My question begins in that point. Up to now I have not seen this comment like #!/bin/bash
. It is always #!/bin/sh
. However, Ubuntu distributions do not have the Bourne Shell program. They have the Bourne Again Shell (bash).
In that point, is it correct to place the comment #!/bin/sh
in shell scripts written in Ubuntu distributions?
bash shell-script shell ubuntu shebang
add a comment |
Generally, shell scripts contain the following comment at the first line of the script file: #!/bin/sh
. According to the researches that I made, this is called "hash bang" and it is conventional comment. This comment informs Unix that this file is executed by the Bourne Shell under the directory /bin
.
My question begins in that point. Up to now I have not seen this comment like #!/bin/bash
. It is always #!/bin/sh
. However, Ubuntu distributions do not have the Bourne Shell program. They have the Bourne Again Shell (bash).
In that point, is it correct to place the comment #!/bin/sh
in shell scripts written in Ubuntu distributions?
bash shell-script shell ubuntu shebang
2
AKA shebang, en.wikipedia.org/wiki/Shebang_(Unix)
– K7AAY
13 hours ago
See my answer to this serverfault question: #!/bin/sh vs #!/bin/bash for maximum portability.
– Gordon Davisson
11 hours ago
add a comment |
Generally, shell scripts contain the following comment at the first line of the script file: #!/bin/sh
. According to the researches that I made, this is called "hash bang" and it is conventional comment. This comment informs Unix that this file is executed by the Bourne Shell under the directory /bin
.
My question begins in that point. Up to now I have not seen this comment like #!/bin/bash
. It is always #!/bin/sh
. However, Ubuntu distributions do not have the Bourne Shell program. They have the Bourne Again Shell (bash).
In that point, is it correct to place the comment #!/bin/sh
in shell scripts written in Ubuntu distributions?
bash shell-script shell ubuntu shebang
Generally, shell scripts contain the following comment at the first line of the script file: #!/bin/sh
. According to the researches that I made, this is called "hash bang" and it is conventional comment. This comment informs Unix that this file is executed by the Bourne Shell under the directory /bin
.
My question begins in that point. Up to now I have not seen this comment like #!/bin/bash
. It is always #!/bin/sh
. However, Ubuntu distributions do not have the Bourne Shell program. They have the Bourne Again Shell (bash).
In that point, is it correct to place the comment #!/bin/sh
in shell scripts written in Ubuntu distributions?
bash shell-script shell ubuntu shebang
bash shell-script shell ubuntu shebang
edited 9 mins ago
Community♦
1
1
asked 13 hours ago
GoktugGoktug
2969
2969
2
AKA shebang, en.wikipedia.org/wiki/Shebang_(Unix)
– K7AAY
13 hours ago
See my answer to this serverfault question: #!/bin/sh vs #!/bin/bash for maximum portability.
– Gordon Davisson
11 hours ago
add a comment |
2
AKA shebang, en.wikipedia.org/wiki/Shebang_(Unix)
– K7AAY
13 hours ago
See my answer to this serverfault question: #!/bin/sh vs #!/bin/bash for maximum portability.
– Gordon Davisson
11 hours ago
2
2
AKA shebang, en.wikipedia.org/wiki/Shebang_(Unix)
– K7AAY
13 hours ago
AKA shebang, en.wikipedia.org/wiki/Shebang_(Unix)
– K7AAY
13 hours ago
See my answer to this serverfault question: #!/bin/sh vs #!/bin/bash for maximum portability.
– Gordon Davisson
11 hours ago
See my answer to this serverfault question: #!/bin/sh vs #!/bin/bash for maximum portability.
– Gordon Davisson
11 hours ago
add a comment |
4 Answers
4
active
oldest
votes
Yes you can use #!/bin/sh
in a script because /bin/sh
is (hopefully) provided for on such systems, usually via a link of some sort that makes bash
behave (more or less) like a sh
would. Here's a Centos7 system, for example, that links sh
to bash
:
-bash-4.2$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec 4 16:48 /bin/sh -> bash
-bash-4.2$
You could also use #!/bin/bash
if you are writing a bash
script only for that system and want to use bash
features. However, such scripts will suffer from portability problems, for example on OpenBSD where bash
is only installed if the admin takes the trouble to install it (I do not) and then it is installed to /usr/local/bin/bash
, not /bin/bash
. A strictly POSIX #!/bin/sh
script should be more portable.
Note this: "When invoked assh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode
– glenn jackman
12 hours ago
2
When I write scripts for RHEL servers at my job, I use#!/bin/bash
precisely so that I can take advantage of non-POSIX features.
– Monty Harder
11 hours ago
@MontyHarder IIRC on RHEL/bin/sh
it's a symlink tobash
, is that correct ? I know for sure on CentOS it is, though.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
#!/bin/sh
should work on all Unix and Unix-like distributions. It is generally thought of as the most portable hashbang so long as your script is kept POSIX compliant.
#!/bin/sh
is normally just a link now as the Bourne shell is no longer maintained. On many Unix systems /bin/sh
will be a link to /bin/ksh
, on many Linux systems it will be a link to /bin/bash
(bash
invoked as sh
is equivalent to running bash --posix
) however on Ubuntu it is a link to /bin/dash
.
It is an important placeholder though because it allows for much greater portability than other methods, so long as your script is strictly POSIX compliant (repeated to stress importance).
Note: When bash
is invoked in POSIX mode it will still allow some non-POSIX things like [[
, arrays, and more. Those things will fail on a non-bash
system.
1
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
1
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to/bin/ash
as well.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
You asked
is it correct to place the comment #!/bin/sh in shell scripts written in ubuntu distributions ?
The answer depends on what you write in the shell script.
If you strictly use portable POSIX-compliant scripts, and don't use any bash-specific commands, then you can use
/bin/sh
.If you know that you are only ever using the script on a machine with bash, and you want to use bash-specific syntax, then you should use
/bin/bash
If you're want to be sure that the script will work on an assortment of unix machines, then you should use only POSIX-compliant syntax, and
/bin/sh
If you regularly use another shell (e.g. ksh, zsh or tcsh), and want to use that syntax in your script, then you should use the appropriate interpreter (like
/bin/ksh93
,/bin/zsh
, or/bin/tcsh
)
New contributor
add a comment |
The "#!" comment does not always use /bin/bash
or /bin/sh
. It just lists whatever the interpreter should be, not just for shell scripting. For example my python scripts usually start with #!/usr/bin/env python
.
Now the difference between #!/bin/sh
and #!/bin/bash
is that /bin/sh
is not always a symlink to /bin/bash
. Often but not always. Ubuntu is a notable exception here. I have seen scripts working fine on CentOS but failing on Ubuntu because author used bash-specific syntax with #!/bin/sh
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496505%2fis-it-correct-to-use-bin-sh-in-the-hashbang-if-the-bourne-shell-isnt-available%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes you can use #!/bin/sh
in a script because /bin/sh
is (hopefully) provided for on such systems, usually via a link of some sort that makes bash
behave (more or less) like a sh
would. Here's a Centos7 system, for example, that links sh
to bash
:
-bash-4.2$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec 4 16:48 /bin/sh -> bash
-bash-4.2$
You could also use #!/bin/bash
if you are writing a bash
script only for that system and want to use bash
features. However, such scripts will suffer from portability problems, for example on OpenBSD where bash
is only installed if the admin takes the trouble to install it (I do not) and then it is installed to /usr/local/bin/bash
, not /bin/bash
. A strictly POSIX #!/bin/sh
script should be more portable.
Note this: "When invoked assh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode
– glenn jackman
12 hours ago
2
When I write scripts for RHEL servers at my job, I use#!/bin/bash
precisely so that I can take advantage of non-POSIX features.
– Monty Harder
11 hours ago
@MontyHarder IIRC on RHEL/bin/sh
it's a symlink tobash
, is that correct ? I know for sure on CentOS it is, though.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
Yes you can use #!/bin/sh
in a script because /bin/sh
is (hopefully) provided for on such systems, usually via a link of some sort that makes bash
behave (more or less) like a sh
would. Here's a Centos7 system, for example, that links sh
to bash
:
-bash-4.2$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec 4 16:48 /bin/sh -> bash
-bash-4.2$
You could also use #!/bin/bash
if you are writing a bash
script only for that system and want to use bash
features. However, such scripts will suffer from portability problems, for example on OpenBSD where bash
is only installed if the admin takes the trouble to install it (I do not) and then it is installed to /usr/local/bin/bash
, not /bin/bash
. A strictly POSIX #!/bin/sh
script should be more portable.
Note this: "When invoked assh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode
– glenn jackman
12 hours ago
2
When I write scripts for RHEL servers at my job, I use#!/bin/bash
precisely so that I can take advantage of non-POSIX features.
– Monty Harder
11 hours ago
@MontyHarder IIRC on RHEL/bin/sh
it's a symlink tobash
, is that correct ? I know for sure on CentOS it is, though.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
Yes you can use #!/bin/sh
in a script because /bin/sh
is (hopefully) provided for on such systems, usually via a link of some sort that makes bash
behave (more or less) like a sh
would. Here's a Centos7 system, for example, that links sh
to bash
:
-bash-4.2$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec 4 16:48 /bin/sh -> bash
-bash-4.2$
You could also use #!/bin/bash
if you are writing a bash
script only for that system and want to use bash
features. However, such scripts will suffer from portability problems, for example on OpenBSD where bash
is only installed if the admin takes the trouble to install it (I do not) and then it is installed to /usr/local/bin/bash
, not /bin/bash
. A strictly POSIX #!/bin/sh
script should be more portable.
Yes you can use #!/bin/sh
in a script because /bin/sh
is (hopefully) provided for on such systems, usually via a link of some sort that makes bash
behave (more or less) like a sh
would. Here's a Centos7 system, for example, that links sh
to bash
:
-bash-4.2$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec 4 16:48 /bin/sh -> bash
-bash-4.2$
You could also use #!/bin/bash
if you are writing a bash
script only for that system and want to use bash
features. However, such scripts will suffer from portability problems, for example on OpenBSD where bash
is only installed if the admin takes the trouble to install it (I do not) and then it is installed to /usr/local/bin/bash
, not /bin/bash
. A strictly POSIX #!/bin/sh
script should be more portable.
answered 13 hours ago
thrigthrig
24.6k23056
24.6k23056
Note this: "When invoked assh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode
– glenn jackman
12 hours ago
2
When I write scripts for RHEL servers at my job, I use#!/bin/bash
precisely so that I can take advantage of non-POSIX features.
– Monty Harder
11 hours ago
@MontyHarder IIRC on RHEL/bin/sh
it's a symlink tobash
, is that correct ? I know for sure on CentOS it is, though.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
Note this: "When invoked assh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode
– glenn jackman
12 hours ago
2
When I write scripts for RHEL servers at my job, I use#!/bin/bash
precisely so that I can take advantage of non-POSIX features.
– Monty Harder
11 hours ago
@MontyHarder IIRC on RHEL/bin/sh
it's a symlink tobash
, is that correct ? I know for sure on CentOS it is, though.
– Sergiy Kolodyazhnyy
7 hours ago
Note this: "When invoked as
sh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode– glenn jackman
12 hours ago
Note this: "When invoked as
sh
, Bash enters POSIX mode after reading the startup files." -- gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode– glenn jackman
12 hours ago
2
2
When I write scripts for RHEL servers at my job, I use
#!/bin/bash
precisely so that I can take advantage of non-POSIX features.– Monty Harder
11 hours ago
When I write scripts for RHEL servers at my job, I use
#!/bin/bash
precisely so that I can take advantage of non-POSIX features.– Monty Harder
11 hours ago
@MontyHarder IIRC on RHEL
/bin/sh
it's a symlink to bash
, is that correct ? I know for sure on CentOS it is, though.– Sergiy Kolodyazhnyy
7 hours ago
@MontyHarder IIRC on RHEL
/bin/sh
it's a symlink to bash
, is that correct ? I know for sure on CentOS it is, though.– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
#!/bin/sh
should work on all Unix and Unix-like distributions. It is generally thought of as the most portable hashbang so long as your script is kept POSIX compliant.
#!/bin/sh
is normally just a link now as the Bourne shell is no longer maintained. On many Unix systems /bin/sh
will be a link to /bin/ksh
, on many Linux systems it will be a link to /bin/bash
(bash
invoked as sh
is equivalent to running bash --posix
) however on Ubuntu it is a link to /bin/dash
.
It is an important placeholder though because it allows for much greater portability than other methods, so long as your script is strictly POSIX compliant (repeated to stress importance).
Note: When bash
is invoked in POSIX mode it will still allow some non-POSIX things like [[
, arrays, and more. Those things will fail on a non-bash
system.
1
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
1
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to/bin/ash
as well.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
#!/bin/sh
should work on all Unix and Unix-like distributions. It is generally thought of as the most portable hashbang so long as your script is kept POSIX compliant.
#!/bin/sh
is normally just a link now as the Bourne shell is no longer maintained. On many Unix systems /bin/sh
will be a link to /bin/ksh
, on many Linux systems it will be a link to /bin/bash
(bash
invoked as sh
is equivalent to running bash --posix
) however on Ubuntu it is a link to /bin/dash
.
It is an important placeholder though because it allows for much greater portability than other methods, so long as your script is strictly POSIX compliant (repeated to stress importance).
Note: When bash
is invoked in POSIX mode it will still allow some non-POSIX things like [[
, arrays, and more. Those things will fail on a non-bash
system.
1
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
1
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to/bin/ash
as well.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
#!/bin/sh
should work on all Unix and Unix-like distributions. It is generally thought of as the most portable hashbang so long as your script is kept POSIX compliant.
#!/bin/sh
is normally just a link now as the Bourne shell is no longer maintained. On many Unix systems /bin/sh
will be a link to /bin/ksh
, on many Linux systems it will be a link to /bin/bash
(bash
invoked as sh
is equivalent to running bash --posix
) however on Ubuntu it is a link to /bin/dash
.
It is an important placeholder though because it allows for much greater portability than other methods, so long as your script is strictly POSIX compliant (repeated to stress importance).
Note: When bash
is invoked in POSIX mode it will still allow some non-POSIX things like [[
, arrays, and more. Those things will fail on a non-bash
system.
#!/bin/sh
should work on all Unix and Unix-like distributions. It is generally thought of as the most portable hashbang so long as your script is kept POSIX compliant.
#!/bin/sh
is normally just a link now as the Bourne shell is no longer maintained. On many Unix systems /bin/sh
will be a link to /bin/ksh
, on many Linux systems it will be a link to /bin/bash
(bash
invoked as sh
is equivalent to running bash --posix
) however on Ubuntu it is a link to /bin/dash
.
It is an important placeholder though because it allows for much greater portability than other methods, so long as your script is strictly POSIX compliant (repeated to stress importance).
Note: When bash
is invoked in POSIX mode it will still allow some non-POSIX things like [[
, arrays, and more. Those things will fail on a non-bash
system.
edited 10 hours ago
answered 12 hours ago
Jesse_bJesse_b
12.2k23064
12.2k23064
1
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
1
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to/bin/ash
as well.
– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
1
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
1
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to/bin/ash
as well.
– Sergiy Kolodyazhnyy
7 hours ago
1
1
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
I'm not sure I'd call it just a placeholder, since it does happen to be path to a standard POSIX shell in most (even if not all) OS's, and the name of the standard shell in the standard itself.
– ilkkachu
10 hours ago
1
1
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to
/bin/ash
as well.– Sergiy Kolodyazhnyy
7 hours ago
"on Ubuntu it is a link to /bin/dash" and in general other Debian-based systems. IIRC on FreeBSD/GhostBSD it's a symlink to
/bin/ash
as well.– Sergiy Kolodyazhnyy
7 hours ago
add a comment |
You asked
is it correct to place the comment #!/bin/sh in shell scripts written in ubuntu distributions ?
The answer depends on what you write in the shell script.
If you strictly use portable POSIX-compliant scripts, and don't use any bash-specific commands, then you can use
/bin/sh
.If you know that you are only ever using the script on a machine with bash, and you want to use bash-specific syntax, then you should use
/bin/bash
If you're want to be sure that the script will work on an assortment of unix machines, then you should use only POSIX-compliant syntax, and
/bin/sh
If you regularly use another shell (e.g. ksh, zsh or tcsh), and want to use that syntax in your script, then you should use the appropriate interpreter (like
/bin/ksh93
,/bin/zsh
, or/bin/tcsh
)
New contributor
add a comment |
You asked
is it correct to place the comment #!/bin/sh in shell scripts written in ubuntu distributions ?
The answer depends on what you write in the shell script.
If you strictly use portable POSIX-compliant scripts, and don't use any bash-specific commands, then you can use
/bin/sh
.If you know that you are only ever using the script on a machine with bash, and you want to use bash-specific syntax, then you should use
/bin/bash
If you're want to be sure that the script will work on an assortment of unix machines, then you should use only POSIX-compliant syntax, and
/bin/sh
If you regularly use another shell (e.g. ksh, zsh or tcsh), and want to use that syntax in your script, then you should use the appropriate interpreter (like
/bin/ksh93
,/bin/zsh
, or/bin/tcsh
)
New contributor
add a comment |
You asked
is it correct to place the comment #!/bin/sh in shell scripts written in ubuntu distributions ?
The answer depends on what you write in the shell script.
If you strictly use portable POSIX-compliant scripts, and don't use any bash-specific commands, then you can use
/bin/sh
.If you know that you are only ever using the script on a machine with bash, and you want to use bash-specific syntax, then you should use
/bin/bash
If you're want to be sure that the script will work on an assortment of unix machines, then you should use only POSIX-compliant syntax, and
/bin/sh
If you regularly use another shell (e.g. ksh, zsh or tcsh), and want to use that syntax in your script, then you should use the appropriate interpreter (like
/bin/ksh93
,/bin/zsh
, or/bin/tcsh
)
New contributor
You asked
is it correct to place the comment #!/bin/sh in shell scripts written in ubuntu distributions ?
The answer depends on what you write in the shell script.
If you strictly use portable POSIX-compliant scripts, and don't use any bash-specific commands, then you can use
/bin/sh
.If you know that you are only ever using the script on a machine with bash, and you want to use bash-specific syntax, then you should use
/bin/bash
If you're want to be sure that the script will work on an assortment of unix machines, then you should use only POSIX-compliant syntax, and
/bin/sh
If you regularly use another shell (e.g. ksh, zsh or tcsh), and want to use that syntax in your script, then you should use the appropriate interpreter (like
/bin/ksh93
,/bin/zsh
, or/bin/tcsh
)
New contributor
New contributor
answered 7 hours ago
StoborStobor
1212
1212
New contributor
New contributor
add a comment |
add a comment |
The "#!" comment does not always use /bin/bash
or /bin/sh
. It just lists whatever the interpreter should be, not just for shell scripting. For example my python scripts usually start with #!/usr/bin/env python
.
Now the difference between #!/bin/sh
and #!/bin/bash
is that /bin/sh
is not always a symlink to /bin/bash
. Often but not always. Ubuntu is a notable exception here. I have seen scripts working fine on CentOS but failing on Ubuntu because author used bash-specific syntax with #!/bin/sh
.
add a comment |
The "#!" comment does not always use /bin/bash
or /bin/sh
. It just lists whatever the interpreter should be, not just for shell scripting. For example my python scripts usually start with #!/usr/bin/env python
.
Now the difference between #!/bin/sh
and #!/bin/bash
is that /bin/sh
is not always a symlink to /bin/bash
. Often but not always. Ubuntu is a notable exception here. I have seen scripts working fine on CentOS but failing on Ubuntu because author used bash-specific syntax with #!/bin/sh
.
add a comment |
The "#!" comment does not always use /bin/bash
or /bin/sh
. It just lists whatever the interpreter should be, not just for shell scripting. For example my python scripts usually start with #!/usr/bin/env python
.
Now the difference between #!/bin/sh
and #!/bin/bash
is that /bin/sh
is not always a symlink to /bin/bash
. Often but not always. Ubuntu is a notable exception here. I have seen scripts working fine on CentOS but failing on Ubuntu because author used bash-specific syntax with #!/bin/sh
.
The "#!" comment does not always use /bin/bash
or /bin/sh
. It just lists whatever the interpreter should be, not just for shell scripting. For example my python scripts usually start with #!/usr/bin/env python
.
Now the difference between #!/bin/sh
and #!/bin/bash
is that /bin/sh
is not always a symlink to /bin/bash
. Often but not always. Ubuntu is a notable exception here. I have seen scripts working fine on CentOS but failing on Ubuntu because author used bash-specific syntax with #!/bin/sh
.
answered 54 mins ago
aragaeraragaer
31314
31314
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496505%2fis-it-correct-to-use-bin-sh-in-the-hashbang-if-the-bourne-shell-isnt-available%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
AKA shebang, en.wikipedia.org/wiki/Shebang_(Unix)
– K7AAY
13 hours ago
See my answer to this serverfault question: #!/bin/sh vs #!/bin/bash for maximum portability.
– Gordon Davisson
11 hours ago