Thursday, May 2, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 2915  / 2 Years ago, mon, january 10, 2022, 10:57:45

If I have turned off execute permissions on hello.sh and try to execute it



~$ sudo chmod 0666 hello.sh
~$ ./hello.sh
-bash: ./hello.sh: Permission denied


I get the permission error. But I can easily override that by using the . or source builtin.



$ . hello.sh
hello everyone


What's the purpose of setting the execute permission on a file if someone can override it using the source builtin?



hello.sh



#!/bin/bash
echo 'hello everyone'

More From » command-line

 Answers
1

There is a difference: if you execute the script like ./script.sh, you are creating a new process, a new instance of the bash shell. This is denied.



However, since the permissions allow you to read the script, what's there to stop you from copy and paste all it contents? The source build-in does only that: it executes the commands one by one by reading them from a text file.


[#35802] Tuesday, January 11, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
warrdel

Total Points: 356
Total Questions: 103
Total Answers: 118

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
;