I have a problem when using "export" command

When I put sudo "export PROXY_LOCAL_NET_IP=10.113.35.108" I get the following error:

sudo: export: command not found

What should I do to resolve this problem?


Solution 1:

You cannot use shell builtins with sudo. Only command corresponding to valid files will be executed through sudo. The correct syntax for sudo is : sudo [options] [filename]

Export is an inside (builtin) command of the Bash shell and possibly some other too.

Also, note that there is no sense to do the action of export via sudo, it has to be done under your user id to be applicable to your shell and its child processes.

If you switch to the root user to do this, you will have to do the rest of your operation as root : this is not recommended. Because if you exit the root shell, the assignement done by export will be lost.

Solution 2:

Become root user with sudo -s and your password.
Then enter your command without sudo:export PROXY_LOCAL_NET_IP=10.113.35.108`

Solution 3:

You can use sudo -E option to use exported variable in a sudo command

The following stackoverflow question has some additional details on how to use environment variable with sudo