What kind of shell is forked by rc.local scripts

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








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 ?







share|improve this question
















  • 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














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 ?







share|improve this question
















  • 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












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 ?







share|improve this question












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 ?









share|improve this question











share|improve this question




share|improve this question










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












  • 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















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491