XK0-004 · Question #340
The following error is encountered when running a script: Which of the following is the cause of this error?
The correct answer is D. The file script. sh does not exist.. The error occurs because the script file does not exist at the specified path, preventing the shell from locating it for execution.
Question
The following error is encountered when running a script:
Which of the following is the cause of this error?
Options
- AScript.sh was not added to the PATH
- BThe $ ! line is incorrect
- CScript.sh is missing the executable bit.
- DThe file script. sh does not exist.
- EBash is not installed on the system
How the community answered
(30 responses)- C3% (1)
- D90% (27)
- E7% (2)
Why each option
The error occurs because the script file does not exist at the specified path, preventing the shell from locating it for execution.
If script.sh were missing from PATH, the shell would return 'command not found', which only applies when invoking a command without a relative or absolute path prefix.
An incorrect shebang line produces a 'bad interpreter' error, which only occurs after the shell has already located and opened the file.
A missing executable bit causes a 'Permission denied' error, which requires the file to exist and be found before the permission check runs.
When a script cannot be found at the given path, the shell returns a 'No such file or directory' error immediately upon invocation. This is distinct from permission or interpreter errors because the file is entirely absent from the filesystem, making all other execution steps unreachable.
An absent bash binary would generate a 'bad interpreter: No such file or directory' referencing the interpreter path, not the script file itself.
Concept tested: Linux script execution file-not-found error diagnosis
Source: https://www.gnu.org/software/bash/manual/bash.html#Invoking-Bash
Topics
Community Discussion
No community discussion yet for this question.