Specify /bin/bash as the interpreter on the first line of an executable script.
Which line is correct?
A shebang starts with #! followed by the interpreter's absolute path, such as #!/bin/bash.
Detailed explanation
#!/bin/bashCorrect. The kernel uses /bin/bash to interpret the script.
Correct. The kernel uses /bin/bash to interpret the script.
#/bin/bashIncorrect. Without ! it is treated as an ordinary comment.
Incorrect. Without ! it is treated as an ordinary comment.
#!/bin/sh bashIncorrect. This passes bash as an argument to /bin/sh rather than selecting Bash itself.
Incorrect. This passes bash as an argument to /bin/sh rather than selecting Bash itself.
#!/usr/bin/bash -cIncorrect. It does not match the requested interpreter and adds an unsuitable -c.
Incorrect. It does not match the requested interpreter and adds an unsuitable -c.
Try it yourself
An example you can run in a temporary verification environment.
script=$(mktemp); printf '%s\n%s\n' '#!/bin/bash' 'printf shebang-ok' > "$script"; chmod u+x "$script"; "$script"; rm -f -- "$script"Expected result
shebang-okKey points
- First two characters are #!
- Absolute interpreter path
- Execute permission
Notes
- Environment: GNU Bash 5.2 / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.