How to get $DESKTOP_SESSION from sudo script?Root's .bashrc not executing on sudo -iExecute sudo without Password?Bash - Get Sudoer Username?Run sudo command within directoryError, even with sudo: “dd: failed to open ‘/dev/sda1’: Permission denied” (dd input piped from gzip)

How are Aircraft Noses Designed?

Is it safe to pay bills over satellite internet?

Advisor asked for my entire slide presentation so she could give the presentation at an international conference

First author doesn't want a co-author to read the whole paper

How to extract *.tgz.part-*?

Proving the order of quaternion group is 8

Company indirectly discriminating against introverts, specifically INTJ

Milk instead of water in bread

How can you tell apart the pronounciation at the end between the "meine" and "meiner" in the daily spoken situation?

Uniform Roe algebra of virtually abelian group is type I C*-algebra?

Does Darwin owe a debt to Hegel?

What's that funny "illo" I keep hearing in Southern Spain?

Did I Traumatize My Puppy?

Word for 'most late'

Why does Principal Vagina say, "no relation" after introducing himself?

Do more Americans want the Bidens investigated than Trump impeached?

Does immunity to fear prevent a mummy's Dreadful Glare from paralyzing a character?

I am often given, occasionally stolen, rarely sold, and never borrowed

Easy way of generating a 50-150W load @12V

Why do military jets sometimes have elevators in a depressed position when parked?

How can I communicate feelings to players without impacting their agency?

Why is technology bad for children?

Encountering former, abusive advisor at a conference

How does a ball bearing door hinge work?



How to get $DESKTOP_SESSION from sudo script?


Root's .bashrc not executing on sudo -iExecute sudo without Password?Bash - Get Sudoer Username?Run sudo command within directoryError, even with sudo: “dd: failed to open ‘/dev/sda1’: Permission denied” (dd input piped from gzip)






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









1

















The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?



#!/bin/bash
echo $DESKTOP_SESSION
echo $XDG_SESSION_DESKTOP
echo $XDG_CURRENT_DESKTOP
echo $SESSION
echo $MDMSESSION
echo $GDMSESSION


Tested on Xubuntu and Mate, the returns are empty.



user:~$ sudo bash '/path/sample.sh' 






user:~$ bash '/path/sample.sh'
mate
mate
MATE


mate
user:~$









share|improve this question

































    1

















    The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?



    #!/bin/bash
    echo $DESKTOP_SESSION
    echo $XDG_SESSION_DESKTOP
    echo $XDG_CURRENT_DESKTOP
    echo $SESSION
    echo $MDMSESSION
    echo $GDMSESSION


    Tested on Xubuntu and Mate, the returns are empty.



    user:~$ sudo bash '/path/sample.sh' 






    user:~$ bash '/path/sample.sh'
    mate
    mate
    MATE


    mate
    user:~$









    share|improve this question





























      1












      1








      1








      The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?



      #!/bin/bash
      echo $DESKTOP_SESSION
      echo $XDG_SESSION_DESKTOP
      echo $XDG_CURRENT_DESKTOP
      echo $SESSION
      echo $MDMSESSION
      echo $GDMSESSION


      Tested on Xubuntu and Mate, the returns are empty.



      user:~$ sudo bash '/path/sample.sh' 






      user:~$ bash '/path/sample.sh'
      mate
      mate
      MATE


      mate
      user:~$









      share|improve this question















      The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?



      #!/bin/bash
      echo $DESKTOP_SESSION
      echo $XDG_SESSION_DESKTOP
      echo $XDG_CURRENT_DESKTOP
      echo $SESSION
      echo $MDMSESSION
      echo $GDMSESSION


      Tested on Xubuntu and Mate, the returns are empty.



      user:~$ sudo bash '/path/sample.sh' 






      user:~$ bash '/path/sample.sh'
      mate
      mate
      MATE


      mate
      user:~$






      sudo desktop-environments






      share|improve this question














      share|improve this question











      share|improve this question




      share|improve this question










      asked May 13 at 17:07









      NicolasSmithNicolasSmith

      4221 gold badge4 silver badges17 bronze badges




      4221 gold badge4 silver badges17 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          2


















          You need to pass -E option to sudo:




          -E, --preserve-env



          Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.




          - see man sudo (or online).



          And run your script as



          sudo -E '/path/sample.sh' 





          share|improve this answer



























            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            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%2f1142924%2fhow-to-get-desktop-session-from-sudo-script%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown


























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2


















            You need to pass -E option to sudo:




            -E, --preserve-env



            Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.




            - see man sudo (or online).



            And run your script as



            sudo -E '/path/sample.sh' 





            share|improve this answer






























              2


















              You need to pass -E option to sudo:




              -E, --preserve-env



              Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.




              - see man sudo (or online).



              And run your script as



              sudo -E '/path/sample.sh' 





              share|improve this answer




























                2














                2










                2









                You need to pass -E option to sudo:




                -E, --preserve-env



                Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.




                - see man sudo (or online).



                And run your script as



                sudo -E '/path/sample.sh' 





                share|improve this answer














                You need to pass -E option to sudo:




                -E, --preserve-env



                Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.




                - see man sudo (or online).



                And run your script as



                sudo -E '/path/sample.sh' 






                share|improve this answer













                share|improve this answer




                share|improve this answer










                answered May 13 at 17:18









                N0rbertN0rbert

                32.7k10 gold badges77 silver badges158 bronze badges




                32.7k10 gold badges77 silver badges158 bronze badges































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1142924%2fhow-to-get-desktop-session-from-sudo-script%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown









                    Popular posts from this blog

                    Tamil (spriik) Luke uk diar | Nawigatjuun

                    Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                    Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?