XK0-005 · Question #10210
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 correct answer is A. chmod u+x shortscript.sh. To execute a shell script, it must have execute permissions, which can be granted using the chmod command.
Question
Options
- Achmod u+x shortscript.sh
- Bsource ./shortscript.sh
- Cchmod 155 ~/shortscript.sh
- Dchgrp shortscript.sh Joe
How the community answered
(55 responses)- A95% (52)
- B2% (1)
- C4% (2)
Why each option
To execute a shell script, it must have execute permissions, which can be granted using the `chmod` command.
When a script is created, by default it typically does not have execute permissions. The `chmod u+x shortscript.sh` command adds execute permission for the user (u) who owns the file, which is necessary for the script to be runnable by that user using `./shortscript.sh`.
source ./shortscript.sh would execute the script in the current shell context but does not directly address the missing execute permission causing the failure.
chmod 155 ~/shortscript.sh would set permissions to `---r-xr-x`, which removes write permission for the owner and grants execute permission only to others, not directly to the owner for execution.
chgrp shortscript.sh Joe changes the group ownership of the file to `Joe`, but this does not affect its executability.
Concept tested: Granting execute permissions to shell scripts
Source: https://man7.org/linux/man-pages/man1/chmod.1.html
Topics
Community Discussion
No community discussion yet for this question.