What kind of shell is forked by rc.local scripts
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
When I try to run a script through rc.local
, I see very minimal
environment variables. I am interested to know why this happens. I could not find anywhere the type of shell forked by rc.local
.
I even tried /bin/bash -l script.sh
, so that it will execute /etc/.profile when executed as login shell. It does add few variables but still lot of them are missing.
Will it be correct to say that rc.local
executes scripts in non-login, non-interactive shell and that's the reason environment variables are not there as .profile will not be sourced and .bashrc will do nothing as shell is non interactive ? As the behavior is similar to crontab, is the reason also same ?
14.04 runlevel
 |Â
show 1 more comment
up vote
0
down vote
favorite
When I try to run a script through rc.local
, I see very minimal
environment variables. I am interested to know why this happens. I could not find anywhere the type of shell forked by rc.local
.
I even tried /bin/bash -l script.sh
, so that it will execute /etc/.profile when executed as login shell. It does add few variables but still lot of them are missing.
Will it be correct to say that rc.local
executes scripts in non-login, non-interactive shell and that's the reason environment variables are not there as .profile will not be sourced and .bashrc will do nothing as shell is non interactive ? As the behavior is similar to crontab, is the reason also same ?
14.04 runlevel
1
/etc/rc.local
is run as root. It is an ordinary script, so what shell runs the script depends on whether the script has a shebang line (#!
) or not. What environment variables were you expecting? The script runs during the boot sequence, in the name of root, so there will not be any variables related to any specific user account.
â AlexP
May 9 at 8:32
Even if I use shebang #!/bin/bash, then also I can't see env variables.
â krrish
May 9 at 8:36
1
What environment variables did you expect?
â AlexP
May 9 at 8:37
I am just curious why I am not getting environment variables like path, home etc, if it is running as root user.
â krrish
May 9 at 10:54
You don't get HOME etc. because nobody has set them. Set them explicitly if you need them, but I don't see what use would those be in a system-wide script. And anyway, PATH should always be set explicitly in any script, otherwise you'll never be able to tell what the commands do.
â AlexP
May 9 at 11:01
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When I try to run a script through rc.local
, I see very minimal
environment variables. I am interested to know why this happens. I could not find anywhere the type of shell forked by rc.local
.
I even tried /bin/bash -l script.sh
, so that it will execute /etc/.profile when executed as login shell. It does add few variables but still lot of them are missing.
Will it be correct to say that rc.local
executes scripts in non-login, non-interactive shell and that's the reason environment variables are not there as .profile will not be sourced and .bashrc will do nothing as shell is non interactive ? As the behavior is similar to crontab, is the reason also same ?
14.04 runlevel
When I try to run a script through rc.local
, I see very minimal
environment variables. I am interested to know why this happens. I could not find anywhere the type of shell forked by rc.local
.
I even tried /bin/bash -l script.sh
, so that it will execute /etc/.profile when executed as login shell. It does add few variables but still lot of them are missing.
Will it be correct to say that rc.local
executes scripts in non-login, non-interactive shell and that's the reason environment variables are not there as .profile will not be sourced and .bashrc will do nothing as shell is non interactive ? As the behavior is similar to crontab, is the reason also same ?
14.04 runlevel
asked May 9 at 7:06
krrish
1062
1062
1
/etc/rc.local
is run as root. It is an ordinary script, so what shell runs the script depends on whether the script has a shebang line (#!
) or not. What environment variables were you expecting? The script runs during the boot sequence, in the name of root, so there will not be any variables related to any specific user account.
â AlexP
May 9 at 8:32
Even if I use shebang #!/bin/bash, then also I can't see env variables.
â krrish
May 9 at 8:36
1
What environment variables did you expect?
â AlexP
May 9 at 8:37
I am just curious why I am not getting environment variables like path, home etc, if it is running as root user.
â krrish
May 9 at 10:54
You don't get HOME etc. because nobody has set them. Set them explicitly if you need them, but I don't see what use would those be in a system-wide script. And anyway, PATH should always be set explicitly in any script, otherwise you'll never be able to tell what the commands do.
â AlexP
May 9 at 11:01
 |Â
show 1 more comment
1
/etc/rc.local
is run as root. It is an ordinary script, so what shell runs the script depends on whether the script has a shebang line (#!
) or not. What environment variables were you expecting? The script runs during the boot sequence, in the name of root, so there will not be any variables related to any specific user account.
â AlexP
May 9 at 8:32
Even if I use shebang #!/bin/bash, then also I can't see env variables.
â krrish
May 9 at 8:36
1
What environment variables did you expect?
â AlexP
May 9 at 8:37
I am just curious why I am not getting environment variables like path, home etc, if it is running as root user.
â krrish
May 9 at 10:54
You don't get HOME etc. because nobody has set them. Set them explicitly if you need them, but I don't see what use would those be in a system-wide script. And anyway, PATH should always be set explicitly in any script, otherwise you'll never be able to tell what the commands do.
â AlexP
May 9 at 11:01
1
1
/etc/rc.local
is run as root. It is an ordinary script, so what shell runs the script depends on whether the script has a shebang line (#!
) or not. What environment variables were you expecting? The script runs during the boot sequence, in the name of root, so there will not be any variables related to any specific user account.â AlexP
May 9 at 8:32
/etc/rc.local
is run as root. It is an ordinary script, so what shell runs the script depends on whether the script has a shebang line (#!
) or not. What environment variables were you expecting? The script runs during the boot sequence, in the name of root, so there will not be any variables related to any specific user account.â AlexP
May 9 at 8:32
Even if I use shebang #!/bin/bash, then also I can't see env variables.
â krrish
May 9 at 8:36
Even if I use shebang #!/bin/bash, then also I can't see env variables.
â krrish
May 9 at 8:36
1
1
What environment variables did you expect?
â AlexP
May 9 at 8:37
What environment variables did you expect?
â AlexP
May 9 at 8:37
I am just curious why I am not getting environment variables like path, home etc, if it is running as root user.
â krrish
May 9 at 10:54
I am just curious why I am not getting environment variables like path, home etc, if it is running as root user.
â krrish
May 9 at 10:54
You don't get HOME etc. because nobody has set them. Set them explicitly if you need them, but I don't see what use would those be in a system-wide script. And anyway, PATH should always be set explicitly in any script, otherwise you'll never be able to tell what the commands do.
â AlexP
May 9 at 11:01
You don't get HOME etc. because nobody has set them. Set them explicitly if you need them, but I don't see what use would those be in a system-wide script. And anyway, PATH should always be set explicitly in any script, otherwise you'll never be able to tell what the commands do.
â AlexP
May 9 at 11:01
 |Â
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2faskubuntu.com%2fquestions%2f1033890%2fwhat-kind-of-shell-is-forked-by-rc-local-scripts%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
1
/etc/rc.local
is run as root. It is an ordinary script, so what shell runs the script depends on whether the script has a shebang line (#!
) or not. What environment variables were you expecting? The script runs during the boot sequence, in the name of root, so there will not be any variables related to any specific user account.â AlexP
May 9 at 8:32
Even if I use shebang #!/bin/bash, then also I can't see env variables.
â krrish
May 9 at 8:36
1
What environment variables did you expect?
â AlexP
May 9 at 8:37
I am just curious why I am not getting environment variables like path, home etc, if it is running as root user.
â krrish
May 9 at 10:54
You don't get HOME etc. because nobody has set them. Set them explicitly if you need them, but I don't see what use would those be in a system-wide script. And anyway, PATH should always be set explicitly in any script, otherwise you'll never be able to tell what the commands do.
â AlexP
May 9 at 11:01