nerdexam
CompTIACompTIA

XK0-005 · Question #260

XK0-005 Question #260: Real Exam Question with Answer & Explanation

The correct answer is A: chmod u+x shortscript.sh. When a user's script fails to execute with ./shortscript.sh, it's typically because it lacks execute permissions; the chmod u+x shortscript.sh command grants the owner execute rights, allowing the script to run.

Scripting, Containers, and Automation

Question

Joe, a user, creates a short shell script, shortscript.sh, and saves it in his home directory with default permissions and paths. He then attempts to run the script by typing ./shortscript.sh, but the command fails to execute. Which of the following commands would have allowed the script to run?

Options

  • Achmod u+x shortscript.sh
  • Bsource ./shortscript.sh
  • Cchmod 155 ~/shortscript.sh
  • Dchgrp shortscript.sh Joe

Explanation

When a user's script fails to execute with ./shortscript.sh, it's typically because it lacks execute permissions; the chmod u+x shortscript.sh command grants the owner execute rights, allowing the script to run.

Common mistakes.

  • B. The source command (or . command) executes a script in the current shell context, which bypasses the need for execute permissions, but it is not the standard way to allow a script to run as an executable via ./scriptname.
  • C. chmod 155 sets the permissions to ---r-xr-x, which removes read and write permissions for the owner and grants execute permissions to the group and others, but not necessarily the owner, making it unsuitable for the user to execute their own script.
  • D. The chgrp command changes the group ownership of a file, which has no effect on the file's execute permissions.

Concept tested. Linux file permissions - execute bit

Reference. https://man7.org/linux/man-pages/man1/chmod.1.html

Topics

#File Permissions#Shell Scripting#chmod#Script Execution

Community Discussion

No community discussion yet for this question.

Full XK0-005 PracticeBrowse All XK0-005 Questions