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

Singing along to guitar chords (harmony)

Should I tell my insurance company I'm making payments on my new car?

Analog is Obtuse!

Does anycast addressing add additional latency in any way?

How to append a matrix element by element?

Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?

How often can a PC check with passive perception during a combat turn?

Does image quality of the lens affect "focus and recompose" technique?

Going to get married soon, should I do it on Dec 31 or Jan 1?

C-152 carb heat on before landing in hot weather?

Find smallest index that is identical to the value in an array

Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?

Why does the A-4 Skyhawk sit nose-up when on ground?

Is my Rep in Stack-Exchange Form?

Do equal angles necessarily mean a polygon is regular?

Should I hide continue button until tasks are completed?

How risky is real estate?

Can a US President have someone sent to prison?

Ending: accusative or not?

STM Microcontroller burns every time

Pull-up sequence accumulator counter

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

What do you call the action of someone tackling a stronger person?

Was touching your nose a greeting in second millenium Mesopotamia?



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 18 mins ago









      icarus

      6,9061 gold badge16 silver badges33 bronze badges




      6,9061 gold badge16 silver badges33 bronze badges










      asked 38 mins 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
























          • 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
            3 mins 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
























          • 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
            3 mins 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
























          • 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
            3 mins 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













          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











          share


          share










          answered 7 mins 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
            3 mins 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
            3 mins 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
          3 mins 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
          3 mins 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