sudo start login shell (-i) and stay at current working directory

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 login to root via



sudo -i


sudo changes the working directory of new shell to root's home directory. I can use following commands to keep working directory of parent shell:



sudo -s
sudo su
...


but none of these invoke login shell, which means that files like /etc/profile.d/foobar.sh are NOT sourced.



How can you you invoke login shell via sudo and stay at the same directory?




EDIT



I can use



sudo zsh -l


The downside is that I'm hard-coding the shell, but that's no big deal, since it probably won't change in my lifetime. :-)







share|improve this question



















  • Have you tried su--preserve-environment? Edit: on mobile, can't test it. I reckon that you could just run sudo (shell) `pwd`" where (shell)` is your shell
    – Stan Strum
    May 17 at 18:29











  • @StanStrum I want to use sudo, because I don't want to type root's password.
    – Mark Howard
    May 17 at 18:31











  • @MarkHoward And the 2nd suggestion?
    – Stan Strum
    May 17 at 18:31










  • @StanStrum that's what's in my EDIT. If you append -l it works.
    – Mark Howard
    May 17 at 18:32










  • You could use getent to look up root's shell, but that might be overkill.
    – Ulrich Schwarz
    May 17 at 20:09














up vote
0
down vote

favorite












When I login to root via



sudo -i


sudo changes the working directory of new shell to root's home directory. I can use following commands to keep working directory of parent shell:



sudo -s
sudo su
...


but none of these invoke login shell, which means that files like /etc/profile.d/foobar.sh are NOT sourced.



How can you you invoke login shell via sudo and stay at the same directory?




EDIT



I can use



sudo zsh -l


The downside is that I'm hard-coding the shell, but that's no big deal, since it probably won't change in my lifetime. :-)







share|improve this question



















  • Have you tried su--preserve-environment? Edit: on mobile, can't test it. I reckon that you could just run sudo (shell) `pwd`" where (shell)` is your shell
    – Stan Strum
    May 17 at 18:29











  • @StanStrum I want to use sudo, because I don't want to type root's password.
    – Mark Howard
    May 17 at 18:31











  • @MarkHoward And the 2nd suggestion?
    – Stan Strum
    May 17 at 18:31










  • @StanStrum that's what's in my EDIT. If you append -l it works.
    – Mark Howard
    May 17 at 18:32










  • You could use getent to look up root's shell, but that might be overkill.
    – Ulrich Schwarz
    May 17 at 20:09












up vote
0
down vote

favorite









up vote
0
down vote

favorite











When I login to root via



sudo -i


sudo changes the working directory of new shell to root's home directory. I can use following commands to keep working directory of parent shell:



sudo -s
sudo su
...


but none of these invoke login shell, which means that files like /etc/profile.d/foobar.sh are NOT sourced.



How can you you invoke login shell via sudo and stay at the same directory?




EDIT



I can use



sudo zsh -l


The downside is that I'm hard-coding the shell, but that's no big deal, since it probably won't change in my lifetime. :-)







share|improve this question











When I login to root via



sudo -i


sudo changes the working directory of new shell to root's home directory. I can use following commands to keep working directory of parent shell:



sudo -s
sudo su
...


but none of these invoke login shell, which means that files like /etc/profile.d/foobar.sh are NOT sourced.



How can you you invoke login shell via sudo and stay at the same directory?




EDIT



I can use



sudo zsh -l


The downside is that I'm hard-coding the shell, but that's no big deal, since it probably won't change in my lifetime. :-)









share|improve this question










share|improve this question




share|improve this question









asked May 17 at 18:23









Mark Howard

113




113











  • Have you tried su--preserve-environment? Edit: on mobile, can't test it. I reckon that you could just run sudo (shell) `pwd`" where (shell)` is your shell
    – Stan Strum
    May 17 at 18:29











  • @StanStrum I want to use sudo, because I don't want to type root's password.
    – Mark Howard
    May 17 at 18:31











  • @MarkHoward And the 2nd suggestion?
    – Stan Strum
    May 17 at 18:31










  • @StanStrum that's what's in my EDIT. If you append -l it works.
    – Mark Howard
    May 17 at 18:32










  • You could use getent to look up root's shell, but that might be overkill.
    – Ulrich Schwarz
    May 17 at 20:09
















  • Have you tried su--preserve-environment? Edit: on mobile, can't test it. I reckon that you could just run sudo (shell) `pwd`" where (shell)` is your shell
    – Stan Strum
    May 17 at 18:29











  • @StanStrum I want to use sudo, because I don't want to type root's password.
    – Mark Howard
    May 17 at 18:31











  • @MarkHoward And the 2nd suggestion?
    – Stan Strum
    May 17 at 18:31










  • @StanStrum that's what's in my EDIT. If you append -l it works.
    – Mark Howard
    May 17 at 18:32










  • You could use getent to look up root's shell, but that might be overkill.
    – Ulrich Schwarz
    May 17 at 20:09















Have you tried su--preserve-environment? Edit: on mobile, can't test it. I reckon that you could just run sudo (shell) `pwd`" where (shell)` is your shell
– Stan Strum
May 17 at 18:29





Have you tried su--preserve-environment? Edit: on mobile, can't test it. I reckon that you could just run sudo (shell) `pwd`" where (shell)` is your shell
– Stan Strum
May 17 at 18:29













@StanStrum I want to use sudo, because I don't want to type root's password.
– Mark Howard
May 17 at 18:31





@StanStrum I want to use sudo, because I don't want to type root's password.
– Mark Howard
May 17 at 18:31













@MarkHoward And the 2nd suggestion?
– Stan Strum
May 17 at 18:31




@MarkHoward And the 2nd suggestion?
– Stan Strum
May 17 at 18:31












@StanStrum that's what's in my EDIT. If you append -l it works.
– Mark Howard
May 17 at 18:32




@StanStrum that's what's in my EDIT. If you append -l it works.
– Mark Howard
May 17 at 18:32












You could use getent to look up root's shell, but that might be overkill.
– Ulrich Schwarz
May 17 at 20:09




You could use getent to look up root's shell, but that might be overkill.
– Ulrich Schwarz
May 17 at 20:09















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f444448%2fsudo-start-login-shell-i-and-stay-at-current-working-directory%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%2funix.stackexchange.com%2fquestions%2f444448%2fsudo-start-login-shell-i-and-stay-at-current-working-directory%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay