nerdexam
CompTIA

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.

Scripting, Containers and Automation

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)
  • C
    3% (1)
  • D
    90% (27)
  • E
    7% (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.

AScript.sh was not added to the PATH

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.

BThe $ ! line is incorrect

An incorrect shebang line produces a 'bad interpreter' error, which only occurs after the shell has already located and opened the file.

CScript.sh is missing the executable bit.

A missing executable bit causes a 'Permission denied' error, which requires the file to exist and be found before the permission check runs.

DThe file script. sh does not exist.Correct

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.

EBash is not installed on the system

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

#shell scripting#bash errors#script debugging#file permissions

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice