Execute a permissioned script directly as ./report.sh.
Use Bash syntax by naming the interpreter on the first line.
Which first line is appropriate?
A #!/bin/bash shebang tells the kernel to execute a directly launched script with Bash.
Detailed explanation
#/bin/bashIncorrect. Without !, this is an ordinary comment.
Incorrect. Without !, this is an ordinary comment.
#!/bin/report.shIncorrect. It names the script itself as the interpreter.
Incorrect. It names the script itself as the interpreter.
#!bash /binIncorrect. A shebang expects the interpreter path immediately after #!.
Incorrect. A shebang expects the interpreter path immediately after #!.
#!/bin/bashCorrect. /bin/bash is specified as the script interpreter.
Correct. /bin/bash is specified as the script interpreter.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'f=$(mktemp); printf "#!/bin/bash\nprintf \"%s\\n\" bash-ok\n" >"$f"; chmod +x "$f"; "$f"; rm -f "$f"'Expected result
bash-okKey points
- #! is the first two characters
- The interpreter path follows
- It is used for direct execution
Notes
- Environment: Linux / 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.