sudo script in my $HOME/bin folder
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a script in my $HOME/bin
folder that must be executed with sudo
.
If I run
sudo <nameofthescript>
I get
sudo: <nameofthescript>: command not found
What is the most preferable way to add this script to the $PATH
of sudo
?
Should I move it in /usr/local/sbin
?
Should I create a /root/bin
folder?
shell-script sudo path
add a comment |Â
up vote
1
down vote
favorite
I have a script in my $HOME/bin
folder that must be executed with sudo
.
If I run
sudo <nameofthescript>
I get
sudo: <nameofthescript>: command not found
What is the most preferable way to add this script to the $PATH
of sudo
?
Should I move it in /usr/local/sbin
?
Should I create a /root/bin
folder?
shell-script sudo path
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a script in my $HOME/bin
folder that must be executed with sudo
.
If I run
sudo <nameofthescript>
I get
sudo: <nameofthescript>: command not found
What is the most preferable way to add this script to the $PATH
of sudo
?
Should I move it in /usr/local/sbin
?
Should I create a /root/bin
folder?
shell-script sudo path
I have a script in my $HOME/bin
folder that must be executed with sudo
.
If I run
sudo <nameofthescript>
I get
sudo: <nameofthescript>: command not found
What is the most preferable way to add this script to the $PATH
of sudo
?
Should I move it in /usr/local/sbin
?
Should I create a /root/bin
folder?
shell-script sudo path
edited Apr 11 at 11:14
Jeff Schaller
31.1k846105
31.1k846105
asked Apr 11 at 11:12
check-emee
418614
418614
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
sudo
sets up a limited PATH
, so it will not find your local script. You can configure it to not env_reset
for a given user and so on, but perhaps the simplest thing is to write your own one-line mysudo
script that does:
#!/bin/sh
exec sudo -s PATH="$PATH" exec "$@"
and then say mysudo somecommand ...
instead of sudo somecommand ...
. It will ask sudo to run a shell, set the PATH
back to what it was, then run your command found in that original path.
add a comment |Â
up vote
0
down vote
PATH
is an environment variable on operating systems like Linux, Windows which has specific set of directories where executable programs are located. According to your question, your executable script is placed under $HOME/bin
directory. So if you want to run a script which is not in PATH, you need to give full file structural path to let OS reach the file to execute it. For example,
sudo $HOME/bin/<nameofthescript>
If you do not want to give full file path all the time, you can put that file path in environment veritable using below command. Consedering, you have kept your script in $HOME/bin
directory.
PATH=$PATH:$HOME/bin
Above command will add your bin directory to the environmental path and then you can use <nameofscript>
from anywhere on the system.
Also, this will only work till the time your bash is running, if you try the same in new terminal, your PATH will change to default. To make it permanent, you need to add below line either in $HOME/.profile
or $HOME/.bashrc
file.
export PATH=$PATH:$HOME/bin
To allow only root user to execute the <nameofscript>
from anywhere, you can either put in under /sbin
or /usr/sbin
directory.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
sudo
sets up a limited PATH
, so it will not find your local script. You can configure it to not env_reset
for a given user and so on, but perhaps the simplest thing is to write your own one-line mysudo
script that does:
#!/bin/sh
exec sudo -s PATH="$PATH" exec "$@"
and then say mysudo somecommand ...
instead of sudo somecommand ...
. It will ask sudo to run a shell, set the PATH
back to what it was, then run your command found in that original path.
add a comment |Â
up vote
1
down vote
accepted
sudo
sets up a limited PATH
, so it will not find your local script. You can configure it to not env_reset
for a given user and so on, but perhaps the simplest thing is to write your own one-line mysudo
script that does:
#!/bin/sh
exec sudo -s PATH="$PATH" exec "$@"
and then say mysudo somecommand ...
instead of sudo somecommand ...
. It will ask sudo to run a shell, set the PATH
back to what it was, then run your command found in that original path.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
sudo
sets up a limited PATH
, so it will not find your local script. You can configure it to not env_reset
for a given user and so on, but perhaps the simplest thing is to write your own one-line mysudo
script that does:
#!/bin/sh
exec sudo -s PATH="$PATH" exec "$@"
and then say mysudo somecommand ...
instead of sudo somecommand ...
. It will ask sudo to run a shell, set the PATH
back to what it was, then run your command found in that original path.
sudo
sets up a limited PATH
, so it will not find your local script. You can configure it to not env_reset
for a given user and so on, but perhaps the simplest thing is to write your own one-line mysudo
script that does:
#!/bin/sh
exec sudo -s PATH="$PATH" exec "$@"
and then say mysudo somecommand ...
instead of sudo somecommand ...
. It will ask sudo to run a shell, set the PATH
back to what it was, then run your command found in that original path.
answered Apr 11 at 12:25
meuh
29.3k11649
29.3k11649
add a comment |Â
add a comment |Â
up vote
0
down vote
PATH
is an environment variable on operating systems like Linux, Windows which has specific set of directories where executable programs are located. According to your question, your executable script is placed under $HOME/bin
directory. So if you want to run a script which is not in PATH, you need to give full file structural path to let OS reach the file to execute it. For example,
sudo $HOME/bin/<nameofthescript>
If you do not want to give full file path all the time, you can put that file path in environment veritable using below command. Consedering, you have kept your script in $HOME/bin
directory.
PATH=$PATH:$HOME/bin
Above command will add your bin directory to the environmental path and then you can use <nameofscript>
from anywhere on the system.
Also, this will only work till the time your bash is running, if you try the same in new terminal, your PATH will change to default. To make it permanent, you need to add below line either in $HOME/.profile
or $HOME/.bashrc
file.
export PATH=$PATH:$HOME/bin
To allow only root user to execute the <nameofscript>
from anywhere, you can either put in under /sbin
or /usr/sbin
directory.
add a comment |Â
up vote
0
down vote
PATH
is an environment variable on operating systems like Linux, Windows which has specific set of directories where executable programs are located. According to your question, your executable script is placed under $HOME/bin
directory. So if you want to run a script which is not in PATH, you need to give full file structural path to let OS reach the file to execute it. For example,
sudo $HOME/bin/<nameofthescript>
If you do not want to give full file path all the time, you can put that file path in environment veritable using below command. Consedering, you have kept your script in $HOME/bin
directory.
PATH=$PATH:$HOME/bin
Above command will add your bin directory to the environmental path and then you can use <nameofscript>
from anywhere on the system.
Also, this will only work till the time your bash is running, if you try the same in new terminal, your PATH will change to default. To make it permanent, you need to add below line either in $HOME/.profile
or $HOME/.bashrc
file.
export PATH=$PATH:$HOME/bin
To allow only root user to execute the <nameofscript>
from anywhere, you can either put in under /sbin
or /usr/sbin
directory.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
PATH
is an environment variable on operating systems like Linux, Windows which has specific set of directories where executable programs are located. According to your question, your executable script is placed under $HOME/bin
directory. So if you want to run a script which is not in PATH, you need to give full file structural path to let OS reach the file to execute it. For example,
sudo $HOME/bin/<nameofthescript>
If you do not want to give full file path all the time, you can put that file path in environment veritable using below command. Consedering, you have kept your script in $HOME/bin
directory.
PATH=$PATH:$HOME/bin
Above command will add your bin directory to the environmental path and then you can use <nameofscript>
from anywhere on the system.
Also, this will only work till the time your bash is running, if you try the same in new terminal, your PATH will change to default. To make it permanent, you need to add below line either in $HOME/.profile
or $HOME/.bashrc
file.
export PATH=$PATH:$HOME/bin
To allow only root user to execute the <nameofscript>
from anywhere, you can either put in under /sbin
or /usr/sbin
directory.
PATH
is an environment variable on operating systems like Linux, Windows which has specific set of directories where executable programs are located. According to your question, your executable script is placed under $HOME/bin
directory. So if you want to run a script which is not in PATH, you need to give full file structural path to let OS reach the file to execute it. For example,
sudo $HOME/bin/<nameofthescript>
If you do not want to give full file path all the time, you can put that file path in environment veritable using below command. Consedering, you have kept your script in $HOME/bin
directory.
PATH=$PATH:$HOME/bin
Above command will add your bin directory to the environmental path and then you can use <nameofscript>
from anywhere on the system.
Also, this will only work till the time your bash is running, if you try the same in new terminal, your PATH will change to default. To make it permanent, you need to add below line either in $HOME/.profile
or $HOME/.bashrc
file.
export PATH=$PATH:$HOME/bin
To allow only root user to execute the <nameofscript>
from anywhere, you can either put in under /sbin
or /usr/sbin
directory.
edited Apr 11 at 11:56
answered Apr 11 at 11:50
Nitesh B.
3711417
3711417
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436983%2fsudo-script-in-my-home-bin-folder%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password