job.sh is readable but has no execute permission.
Run its contents as a script in a new Bash process.
Which command is appropriate?
bash job.sh starts Bash and reads job.sh as input, so the script file itself does not need the execute bit.
Detailed explanation
exec job.shIncorrect. exec job.sh treats the file as an executable and also requires execute permission.
Incorrect. exec job.sh treats the file as an executable and also requires execute permission.
./job.shIncorrect. Direct execution of ./job.sh requires the execute bit.
Incorrect. Direct execution of ./job.sh requires the execute bit.
. job.shIncorrect. . job.sh sources the file in the current shell rather than starting a new Bash.
Incorrect. . job.sh sources the file in the current shell rather than starting a new Bash.
bash job.shCorrect. bash job.sh reads the file as Bash input.
Correct. bash job.sh reads the file as Bash input.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); printf 'echo ran\n' >"$tmp/job.sh"; chmod 600 "$tmp/job.sh"; bash "$tmp/job.sh"; rm -rf "$tmp"Expected result
ranKey points
- Bash reads the script
- Read permission is needed
- Direct execution requires x permission
Notes
- Environment: Bash 5.x / 一時スクリプト
- 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.