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.
#!/bin/report.shIncorrect. It names the script itself as the interpreter.
#!bash /binIncorrect. A shebang expects the interpreter path immediately after #!.
#!/bin/bashCorrect. /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
Shell function
A reusable group of commands that runs in the caller's shell context.
Positional parameter
A numbered argument or special value supplied to a script or function.
Control flow
Conditions, loops, and exit statuses determine which shell commands run.