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.
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
sourcecommand (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 155sets 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
chgrpcommand 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
Community Discussion
No community discussion yet for this question.