010-160 · Question #24
The current directory contains the following file: -rw-r--r-- 1 root exec 24551 Apr 2 12:36 test.sh The file contains a valid shell script, but executing this file using ./test.sh leads to this…
The correct answer is B. The execute bit should be set in the file's permissions. The 'Permission denied' error for ./test.sh occurs because the file lacks the execute bit; adding it with chmod makes the script runnable.
Question
Options
- AThe file's extension should be changed from .sh to .bin.
- BThe execute bit should be set in the file's permissions.
- CThe user executing the script should be added to the exec group.
- DThe SUID bit should be set in the file's permissions.
- EThe script should be run using #!/test.sh instead of ./test.sh.
How the community answered
(44 responses)- A7% (3)
- B89% (39)
- C2% (1)
- D2% (1)
Why each option
The 'Permission denied' error for ./test.sh occurs because the file lacks the execute bit; adding it with chmod makes the script runnable.
Linux file executability is determined entirely by the execute permission bit, not by the filename extension; renaming .sh to .bin has no effect on permissions.
The listed permissions -rw-r--r-- show no execute bit is set for the owner, group, or others. Running 'chmod +x test.sh' adds the execute bit, which is the flag the Linux kernel checks before loading and running a file. Without the execute bit, the kernel rejects execution regardless of the file's valid script content.
The file's group 'exec' has only read permission as shown by -rw-r--r--, so joining that group does not grant execute rights; the execute bit itself must be set on the file.
The SUID bit causes a script to run with the file owner's effective UID, but it does not grant execute permission; the execute bit is still required before the kernel will run the file at all.
#!/test.sh is not a valid way to invoke a script from the command line; the shebang belongs on the first line inside the script file as the interpreter directive, not as a shell command.
Concept tested: Linux file execute permission bit and chmod
Source: https://man7.org/linux/man-pages/man1/chmod.1.html
Topics
Community Discussion
No community discussion yet for this question.