For executing a shell script in current shell, we need to use a period .
or a source
command. But why does it not work with a sudo
permission?
I have a script with execute permission called setup.sh
. When I use a period, I get this:
$ sudo . ./setup.sh sudo: .: command not found
The source
command also produces a similar error. Am I missing out something? What should I do to run the script with sudo
permission in the same/current shell?
Thanks in advance..
Therefore, to run a shell script or program as root, you need to use sudo command. However, sudo only recognizes and runs commands that exist in directories specified in the secure_path in the /etc/sudoers, unless a command is present in the secure_path, you'll counter an error such as the one below.
We can provide the executable permission by using the below command, chmod +x filename.sh. chmod (Change Mode) - Using chmod we can change the access permissions to file system objects. +x - It makes the file executable.
SH file as a root User. Type your user password and hit Enter to execute the . SH file. You can also use su command to login with superuser and execute the .
I'm not sure if this breaks any rules but
sudo bash script.sh
seems to work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With