Score:0

How can I run a script with sudo? I get ".: command not found"

ve flag

I want to run a script, but the script has some cds in it so I have to run it like this

. /scriptfile

This works but I also have some sudos in the script as well. While everything is working but I wanted to try running the entire script with sudo so that I can remove all sudos from the script file.
But, I couldn't run the following (with sudo)

sudo . /scriptfile

by trying to run I get

sudo: .: command not found  

Is there any workaround for this?

Nmath avatar
ng flag
can you include more details and context? The script itself would probably be helpful. Also if you would include the exact input alongside the complete corresponding output so that we can understand the problem
Score:4
cn flag

You need to run

sudo ./scriptfile

You tried

sudo . /scriptfile

which is different due to the space after the dot. . or it's equivalent source is a shell builtin, not a command. That's why the command you tried produces the error sudo: .: command not found.

Note:

./scriptfile

will execute the file with the name scriptfile in the current directory. The file needs to be executable.

. /scriptfile

will source the file /scriptfile (remind that this is an absolute path here). The file doesn't need to be executable to do this, it only needs to be readable.

Score:0
tr flag

Run sudo su beforehand, then you can just run ./scriptfile

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.