Which is not searching full $PATH

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset.



I can see this by running sudo echo $PATH and comparing the paths searched.



$ sudo which abc
which: no abc in (/sbin:/bin:/usr/sbin:/usr/bin)

$ sudo echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin


What is happening here?







share|improve this question





















  • And where is abc actually located ?
    – steve
    Jul 28 at 10:50






  • 2




    Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo....
    – steve
    Jul 28 at 10:52






  • 1




    Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers.
    – steeldriver
    Jul 28 at 11:25
















up vote
0
down vote

favorite












If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset.



I can see this by running sudo echo $PATH and comparing the paths searched.



$ sudo which abc
which: no abc in (/sbin:/bin:/usr/sbin:/usr/bin)

$ sudo echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin


What is happening here?







share|improve this question





















  • And where is abc actually located ?
    – steve
    Jul 28 at 10:50






  • 2




    Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo....
    – steve
    Jul 28 at 10:52






  • 1




    Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers.
    – steeldriver
    Jul 28 at 11:25












up vote
0
down vote

favorite









up vote
0
down vote

favorite











If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset.



I can see this by running sudo echo $PATH and comparing the paths searched.



$ sudo which abc
which: no abc in (/sbin:/bin:/usr/sbin:/usr/bin)

$ sudo echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin


What is happening here?







share|improve this question













If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset.



I can see this by running sudo echo $PATH and comparing the paths searched.



$ sudo which abc
which: no abc in (/sbin:/bin:/usr/sbin:/usr/bin)

$ sudo echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin


What is happening here?









share|improve this question












share|improve this question




share|improve this question








edited Jul 28 at 11:57









ctrl-alt-delor

8,54031946




8,54031946









asked Jul 28 at 10:46









Jethro

1033




1033











  • And where is abc actually located ?
    – steve
    Jul 28 at 10:50






  • 2




    Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo....
    – steve
    Jul 28 at 10:52






  • 1




    Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers.
    – steeldriver
    Jul 28 at 11:25
















  • And where is abc actually located ?
    – steve
    Jul 28 at 10:50






  • 2




    Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo....
    – steve
    Jul 28 at 10:52






  • 1




    Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers.
    – steeldriver
    Jul 28 at 11:25















And where is abc actually located ?
– steve
Jul 28 at 10:50




And where is abc actually located ?
– steve
Jul 28 at 10:50




2




2




Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo....
– steve
Jul 28 at 10:52




Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo....
– steve
Jul 28 at 10:52




1




1




Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers.
– steeldriver
Jul 28 at 11:25




Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers.
– steeldriver
Jul 28 at 11:25










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










$PATH is expanded before sudo is run. Therefore you are seeing the value of PATH for you, and not for the user you sudo to.



try this instead:



$ sudo bash -c 'echo $PATH'





share|improve this answer























    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%2f459027%2fwhich-is-not-searching-full-path%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    $PATH is expanded before sudo is run. Therefore you are seeing the value of PATH for you, and not for the user you sudo to.



    try this instead:



    $ sudo bash -c 'echo $PATH'





    share|improve this answer



























      up vote
      4
      down vote



      accepted










      $PATH is expanded before sudo is run. Therefore you are seeing the value of PATH for you, and not for the user you sudo to.



      try this instead:



      $ sudo bash -c 'echo $PATH'





      share|improve this answer

























        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        $PATH is expanded before sudo is run. Therefore you are seeing the value of PATH for you, and not for the user you sudo to.



        try this instead:



        $ sudo bash -c 'echo $PATH'





        share|improve this answer















        $PATH is expanded before sudo is run. Therefore you are seeing the value of PATH for you, and not for the user you sudo to.



        try this instead:



        $ sudo bash -c 'echo $PATH'






        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jul 28 at 21:22









        slm♦

        232k65479649




        232k65479649











        answered Jul 28 at 10:49









        ctrl-alt-delor

        8,54031946




        8,54031946






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459027%2fwhich-is-not-searching-full-path%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