350-201 · Question #20
An engineer has created a bash script to automate a complicated process. During script execution, this error occurs: permission denied. Which command must be added to execute this script?
The correct answer is A. chmod +x ex.sh. The 'permission denied' error indicates the script file lacks execute permission. The chmod +x command grants that permission so the script can be run directly.
Question
An engineer has created a bash script to automate a complicated process. During script execution, this error occurs: permission denied. Which command must be added to execute this script?
Options
- Achmod +x ex.sh
- Bsource ex.sh
- Cchroot ex.sh
- Dsh ex.sh
How the community answered
(35 responses)- A91% (32)
- B3% (1)
- C6% (2)
Why each option
The 'permission denied' error indicates the script file lacks execute permission. The chmod +x command grants that permission so the script can be run directly.
chmod +x modifies the file's permission bits to add the execute flag for the owner, group, and others, which directly resolves a 'permission denied' error when attempting to run a shell script. Without this flag set, the operating system refuses to execute the file as a program regardless of its content.
source reads and executes the script in the current shell context without requiring the execute bit, but it does not grant execute permission and is not the standard fix for a permission denied error.
chroot changes the apparent root directory for a running process and has no relationship to file execute permissions.
sh ex.sh invokes the shell interpreter directly with the script as an argument and bypasses the execute permission check, but it does not add execute permission to the file itself as the question requires.
Concept tested: Linux file execute permissions using chmod
Source: https://www.gnu.org/software/coreutils/manual/html_node/chmod-invocation.html
Topics
Community Discussion
No community discussion yet for this question.