exam questions

Exam XK0-004 All Questions

View all questions & answers for the XK0-004 exam

Exam XK0-004 topic 1 question 126 discussion

Actual exam question from CompTIA's XK0-004
Question #: 126
Topic #: 1
[All XK0-004 Questions]

An administrator has written the following Bash script:

All necessary files exist in the correct locations. However, when the administrator executes /home/user/test.sh the following error is received:

No such file or directory -
Which of the following is the MOST likely cause of the error?

  • A. The shebang points to the wrong path.
  • B. The script is not executable.
  • C. The formatting of the file is incorrect.
  • D. Nslookup is not installed.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
xeun88
2 years, 7 months ago
The shebang part should always start with #!/bin.bash
upvoted 1 times
...
Dracolitch
3 years, 2 months ago
A is correct, /usr/bin/sh is a symbolic link not a file, the syntax can be used with the backtic as shown or $(cat /home/user/iplist.txt) both will work *Tested If the file wasnt executable you would get the error command not found similar issue for D. However if the location that lists the interpreter doesnt have the appropriate file location, you would receive the following error: zsh: ./test.sh: bad interpreter: /usr/bin/sh: no such file or directory I wish CompTIA would fix their questions, include the whole error or dont use the question at all, this question isnt a true test of what you will see in the real world.
upvoted 3 times
...
shahin_am2
4 years ago
A is correct because shebang "MUST" be in the first two bytes at the start of an executable file. https://stackoverflow.com/a/12911604/13282838
upvoted 2 times
...
Icarus1987
4 years ago
I tested this in lab. The correct answer is A assuming the /usr/bin/sh has been deleted, moved or renamed. In my lab I executed the script and it worked. Then I renamed /usr/bin/sh to /usr/bin/sh.old then ran the script again and got the error: "bash: ./test.sh: /usr/bin/sh: bad interpreter: No such file or directory". So as usual CompTIA lied to us when they said "All necessary files exist in the correct locations" because the /usr/bin/sh binary clearly wasn't present from that system they used when writing this question.
upvoted 2 times
DBB73
3 years, 6 months ago
"So as usual CompTIA lied to us when they said "All necessary files exist in the correct locations" because the /usr/bin/sh binary clearly wasn't present from that system they used when writing this question." --And this is why the question is here and most likely not on the exam. It is not the first time that a question has been thrown out because it is incorrect.
upvoted 1 times
...
Icarus1987
4 years ago
I bet CompTIA is trying to confuse us because /usr/bin/sh is a Symbolic Link and they (CompTIA) don't consider it a file. /usb/bin/sh points to bash: [root@centos root]# ls -l /usr/bin/sh lrwxrwxrwx. 1 root root 4 Jul 21 2020 /usr/bin/sh -> bash
upvoted 2 times
...
...
[Removed]
4 years, 1 month ago
If I point to wrong interpreter, I get the message: bash: ./test.sh: /usr/bin/shb: bad interpreter: No such file or directory So, A or The shabang points to the wrong path is the correct answer.
upvoted 2 times
...
miky_Cissp
4 years, 1 month ago
I tested it out using #! /bin/bash; the script does not work. "$" is missing before cat. I vote for B. (Assuming all files exist in the right location might mean that there is an interpreter in the mentioned path ).
upvoted 1 times
...
Sfutrell
4 years, 1 month ago
The shebang line is the absolute path to the Bash interpreter, and the interpreter usually lives in /bin/bash, so I am going with A.
upvoted 1 times
...
FilipIT
4 years, 3 months ago
A is Correct .
upvoted 4 times
...
giannisae
4 years, 3 months ago
All necessary files exist in the correct locations B is the correct answer
upvoted 1 times
Aamm033
2 years, 7 months ago
if the script is not executable you will receive an error message: -bash: ./lines.sh: Permission denied with sudo sudo: ./test.sh: command not found
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago