Running a command repeatedly with different environmentsu or sudo keeping/removing certain environment...

Is this one of the engines from the 9/11 aircraft?

Do sudoku answers always have a single minimal clue set?

How can I convince my reader that I will not use a certain trope?

How to positively portray high and mighty characters?

Why is the Turkish president's surname spelt in Russian as Эрдоган, with г?

Symbolic equivalent of chmod 400

Do French speakers not use the subjunctive informally?

When is it ok to add filler to a story?

Transition from ascending to descending a rope

Should I declare a faux wood object to customs when entering Australia?

How could mana leakage be dangerous to a elf?

Layout of complex table

How to determine what is the correct level of detail when modelling?

Alphabet completion rate

How many satellites can stay in a Lagrange point?

The use of "I" and "we" used in the same sentence and other questions

Does the posterior necessarily follow the same conditional dependence structure as the prior?

Mount a folder with a space on Linux

How to append a matrix element by element?

Is there a short way to compare many values mutually at same time without using multiple 'and's?

Why is C++ initial allocation so much larger than C's?

Counting occurrence of words in table is slow

Do equal angles necessarily mean a polygon is regular?

Is there any set of 2-6 notes that doesn't have a chord name?



Running a command repeatedly with different environment


su or sudo keeping/removing certain environment variablesSetting environment vars containing space with envWhy do `env var=value` allow arbitrary name in var?Substitute variable in value of chpst loaded environment variableHow to modify the shell environment seen by apps initiated via desktop?sudo: allow one command to set one environment variableWhy can't I print a variable I can see in the output of env?How to set specific value of DISPLAY variable on remote host with SSH but without command line parameters?Same process has different environmental variables in /proc/pid/environ when seen from different sessions. Why?How to persist environment variables in ash, the Almquist shell?






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







0















Let's say I want to run the process foo with different variables set, like:



FOO=1 foo
FOO=2 foo
FOO=1 BAR=7 foo


How can do do this without repeating the foo command repeatedly? E.g., by looping over the environment to set, like:



for e in 'FOO=1' 'FOO=2' 'FOO=1 BAR=7'; do
env "$e" foo
done


That almost works, except in the case with $e equal to FOO=1 BAR=1, FOO gets set to 1 BAR=1 and BAR doesn't get set at all because env sees a single argument. I could use env $e, i.e., without quoting e - but then it doesn't work if the variable values have spaces.










share|improve this question































    0















    Let's say I want to run the process foo with different variables set, like:



    FOO=1 foo
    FOO=2 foo
    FOO=1 BAR=7 foo


    How can do do this without repeating the foo command repeatedly? E.g., by looping over the environment to set, like:



    for e in 'FOO=1' 'FOO=2' 'FOO=1 BAR=7'; do
    env "$e" foo
    done


    That almost works, except in the case with $e equal to FOO=1 BAR=1, FOO gets set to 1 BAR=1 and BAR doesn't get set at all because env sees a single argument. I could use env $e, i.e., without quoting e - but then it doesn't work if the variable values have spaces.










    share|improve this question



























      0












      0








      0








      Let's say I want to run the process foo with different variables set, like:



      FOO=1 foo
      FOO=2 foo
      FOO=1 BAR=7 foo


      How can do do this without repeating the foo command repeatedly? E.g., by looping over the environment to set, like:



      for e in 'FOO=1' 'FOO=2' 'FOO=1 BAR=7'; do
      env "$e" foo
      done


      That almost works, except in the case with $e equal to FOO=1 BAR=1, FOO gets set to 1 BAR=1 and BAR doesn't get set at all because env sees a single argument. I could use env $e, i.e., without quoting e - but then it doesn't work if the variable values have spaces.










      share|improve this question
















      Let's say I want to run the process foo with different variables set, like:



      FOO=1 foo
      FOO=2 foo
      FOO=1 BAR=7 foo


      How can do do this without repeating the foo command repeatedly? E.g., by looping over the environment to set, like:



      for e in 'FOO=1' 'FOO=2' 'FOO=1 BAR=7'; do
      env "$e" foo
      done


      That almost works, except in the case with $e equal to FOO=1 BAR=1, FOO gets set to 1 BAR=1 and BAR doesn't get set at all because env sees a single argument. I could use env $e, i.e., without quoting e - but then it doesn't work if the variable values have spaces.







      bash environment-variables






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      icarus

      6,9061 gold badge16 silver badges33 bronze badges




      6,9061 gold badge16 silver badges33 bronze badges










      asked 2 hours ago









      BeeOnRopeBeeOnRope

      2591 silver badge11 bronze badges




      2591 silver badge11 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You are not going to get much shorter. If the issue is that the command you want to run is long, you might write a helper function, e.g.



          r(){ env "$@" foo with lots of args ; }
          r FOO=1
          r FOO=2
          r FOO=1 BAR=7
          r FOO='1 BAR=7'


          If there is a character you know is not going to be in either the names or the values of the environment variables you could use this to split, or you can attempt to quote the values correctly and use eval.



          The question is why do you want to do this?






          share|improve this answer
























          • The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

            – BeeOnRope
            2 hours ago














          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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/3.0/"u003ecc by-sa 3.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%2funix.stackexchange.com%2fquestions%2f526442%2frunning-a-command-repeatedly-with-different-environment%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









          0














          You are not going to get much shorter. If the issue is that the command you want to run is long, you might write a helper function, e.g.



          r(){ env "$@" foo with lots of args ; }
          r FOO=1
          r FOO=2
          r FOO=1 BAR=7
          r FOO='1 BAR=7'


          If there is a character you know is not going to be in either the names or the values of the environment variables you could use this to split, or you can attempt to quote the values correctly and use eval.



          The question is why do you want to do this?






          share|improve this answer
























          • The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

            – BeeOnRope
            2 hours ago
















          0














          You are not going to get much shorter. If the issue is that the command you want to run is long, you might write a helper function, e.g.



          r(){ env "$@" foo with lots of args ; }
          r FOO=1
          r FOO=2
          r FOO=1 BAR=7
          r FOO='1 BAR=7'


          If there is a character you know is not going to be in either the names or the values of the environment variables you could use this to split, or you can attempt to quote the values correctly and use eval.



          The question is why do you want to do this?






          share|improve this answer
























          • The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

            – BeeOnRope
            2 hours ago














          0












          0








          0







          You are not going to get much shorter. If the issue is that the command you want to run is long, you might write a helper function, e.g.



          r(){ env "$@" foo with lots of args ; }
          r FOO=1
          r FOO=2
          r FOO=1 BAR=7
          r FOO='1 BAR=7'


          If there is a character you know is not going to be in either the names or the values of the environment variables you could use this to split, or you can attempt to quote the values correctly and use eval.



          The question is why do you want to do this?






          share|improve this answer













          You are not going to get much shorter. If the issue is that the command you want to run is long, you might write a helper function, e.g.



          r(){ env "$@" foo with lots of args ; }
          r FOO=1
          r FOO=2
          r FOO=1 BAR=7
          r FOO='1 BAR=7'


          If there is a character you know is not going to be in either the names or the values of the environment variables you could use this to split, or you can attempt to quote the values correctly and use eval.



          The question is why do you want to do this?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          icarusicarus

          6,9061 gold badge16 silver badges33 bronze badges




          6,9061 gold badge16 silver badges33 bronze badges













          • The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

            – BeeOnRope
            2 hours ago



















          • The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

            – BeeOnRope
            2 hours ago

















          The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

          – BeeOnRope
          2 hours ago





          The question is why do you want to do this? To avoiding the repeating the foo command (which is much more complex than just foo). Also to allow the possibility of having tested loops, e.g. 5 possible environments in one list, and 3 in another, and then nested loops to try all 5*3=15 combinations.

          – BeeOnRope
          2 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • 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%2funix.stackexchange.com%2fquestions%2f526442%2frunning-a-command-repeatedly-with-different-environment%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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m