Redirecting streams in bash shell - how to make unconditional on the rest of shell command line

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
1
down vote

favorite












I noted apt output is different when executed alone in Bash shell and when output is redirected to files.



For example:



$ apt install ./*.deb --simulate 1>111.txt 2>222.txt


adding redirection results in text WARNING: apt does not have a stable CLI interface. Use with caution in scripts. in file for stream 2, whereas running apt w/out redirection does not display this text in shell window.



Why output depends on redirection? Maybe apt sees redirection as its` parameter? How can I write redirection to be unnoticed to other part of shell command line?



P.S. I saw it in Ubuntu 18 and apt is specific app, but maybe the issue is general to Unix, so I put only shell in tag.







share|improve this question



























    up vote
    1
    down vote

    favorite












    I noted apt output is different when executed alone in Bash shell and when output is redirected to files.



    For example:



    $ apt install ./*.deb --simulate 1>111.txt 2>222.txt


    adding redirection results in text WARNING: apt does not have a stable CLI interface. Use with caution in scripts. in file for stream 2, whereas running apt w/out redirection does not display this text in shell window.



    Why output depends on redirection? Maybe apt sees redirection as its` parameter? How can I write redirection to be unnoticed to other part of shell command line?



    P.S. I saw it in Ubuntu 18 and apt is specific app, but maybe the issue is general to Unix, so I put only shell in tag.







    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I noted apt output is different when executed alone in Bash shell and when output is redirected to files.



      For example:



      $ apt install ./*.deb --simulate 1>111.txt 2>222.txt


      adding redirection results in text WARNING: apt does not have a stable CLI interface. Use with caution in scripts. in file for stream 2, whereas running apt w/out redirection does not display this text in shell window.



      Why output depends on redirection? Maybe apt sees redirection as its` parameter? How can I write redirection to be unnoticed to other part of shell command line?



      P.S. I saw it in Ubuntu 18 and apt is specific app, but maybe the issue is general to Unix, so I put only shell in tag.







      share|improve this question













      I noted apt output is different when executed alone in Bash shell and when output is redirected to files.



      For example:



      $ apt install ./*.deb --simulate 1>111.txt 2>222.txt


      adding redirection results in text WARNING: apt does not have a stable CLI interface. Use with caution in scripts. in file for stream 2, whereas running apt w/out redirection does not display this text in shell window.



      Why output depends on redirection? Maybe apt sees redirection as its` parameter? How can I write redirection to be unnoticed to other part of shell command line?



      P.S. I saw it in Ubuntu 18 and apt is specific app, but maybe the issue is general to Unix, so I put only shell in tag.









      share|improve this question












      share|improve this question




      share|improve this question








      edited 2 days ago









      slm♦

      232k65479648




      232k65479648









      asked 2 days ago









      Alexei Martianov

      23211




      23211




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          apt has been designed historically with interactive command-line use in mind, hence the coded warning, which has been done on purpose in/by apt and not by the shell.



          However, apt is not necessarily parsing the command line; the shell has already done that job by the time it calls apt. What apt is doing is detecting that the stdout stream has been changed/redirected.



          As for using apt in scripts, you have got the similar older command apt-get which does does more or less the same thing, and does not give that warning when stdout is redirected.



          TLDR Is not the shell writing the error message in stderr, it is the apt command.



          The fact that you are able to capture the apt stderr output in the shell is an artifact of Unix being a multitasking OS, and does not mean it is the shell producing that output.



          PS. Doing an strace at the command, it can be seen apt writing that message:



          strace apt get install bash > a
          ....
          write(2, "n", 1
          ) = 1
          write(2, "WARNING: ", 9WARNING: ) = 9
          write(2, "apt", 3apt) = 3
          write(2, " ", 1 ) = 1
          write(2, "does not have a stable CLI inter"..., 38does not have a stable CLI interface. ) = 38
          write(2, "Use with caution in scripts.", 28Use with caution in scripts.) = 28
          write(2, "n", 1
          ) = 1
          write(2, "n", 1
          ) = 1





          share|improve this answer























          • Is there any way to prevent e.g. apt from detecting redirection?
            – Alexei Martianov
            2 days ago






          • 1




            The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
            – Rui F Ribeiro
            2 days ago











          • What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
            – Alexei Martianov
            2 days ago






          • 1




            That is a whole different question actually. There is the script command for saving sessions of work.
            – Rui F Ribeiro
            2 days ago











          • script is what I can use, thanx!
            – Alexei Martianov
            2 days 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',
          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%2f460503%2fredirecting-streams-in-bash-shell-how-to-make-unconditional-on-the-rest-of-she%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
          2
          down vote













          apt has been designed historically with interactive command-line use in mind, hence the coded warning, which has been done on purpose in/by apt and not by the shell.



          However, apt is not necessarily parsing the command line; the shell has already done that job by the time it calls apt. What apt is doing is detecting that the stdout stream has been changed/redirected.



          As for using apt in scripts, you have got the similar older command apt-get which does does more or less the same thing, and does not give that warning when stdout is redirected.



          TLDR Is not the shell writing the error message in stderr, it is the apt command.



          The fact that you are able to capture the apt stderr output in the shell is an artifact of Unix being a multitasking OS, and does not mean it is the shell producing that output.



          PS. Doing an strace at the command, it can be seen apt writing that message:



          strace apt get install bash > a
          ....
          write(2, "n", 1
          ) = 1
          write(2, "WARNING: ", 9WARNING: ) = 9
          write(2, "apt", 3apt) = 3
          write(2, " ", 1 ) = 1
          write(2, "does not have a stable CLI inter"..., 38does not have a stable CLI interface. ) = 38
          write(2, "Use with caution in scripts.", 28Use with caution in scripts.) = 28
          write(2, "n", 1
          ) = 1
          write(2, "n", 1
          ) = 1





          share|improve this answer























          • Is there any way to prevent e.g. apt from detecting redirection?
            – Alexei Martianov
            2 days ago






          • 1




            The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
            – Rui F Ribeiro
            2 days ago











          • What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
            – Alexei Martianov
            2 days ago






          • 1




            That is a whole different question actually. There is the script command for saving sessions of work.
            – Rui F Ribeiro
            2 days ago











          • script is what I can use, thanx!
            – Alexei Martianov
            2 days ago














          up vote
          2
          down vote













          apt has been designed historically with interactive command-line use in mind, hence the coded warning, which has been done on purpose in/by apt and not by the shell.



          However, apt is not necessarily parsing the command line; the shell has already done that job by the time it calls apt. What apt is doing is detecting that the stdout stream has been changed/redirected.



          As for using apt in scripts, you have got the similar older command apt-get which does does more or less the same thing, and does not give that warning when stdout is redirected.



          TLDR Is not the shell writing the error message in stderr, it is the apt command.



          The fact that you are able to capture the apt stderr output in the shell is an artifact of Unix being a multitasking OS, and does not mean it is the shell producing that output.



          PS. Doing an strace at the command, it can be seen apt writing that message:



          strace apt get install bash > a
          ....
          write(2, "n", 1
          ) = 1
          write(2, "WARNING: ", 9WARNING: ) = 9
          write(2, "apt", 3apt) = 3
          write(2, " ", 1 ) = 1
          write(2, "does not have a stable CLI inter"..., 38does not have a stable CLI interface. ) = 38
          write(2, "Use with caution in scripts.", 28Use with caution in scripts.) = 28
          write(2, "n", 1
          ) = 1
          write(2, "n", 1
          ) = 1





          share|improve this answer























          • Is there any way to prevent e.g. apt from detecting redirection?
            – Alexei Martianov
            2 days ago






          • 1




            The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
            – Rui F Ribeiro
            2 days ago











          • What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
            – Alexei Martianov
            2 days ago






          • 1




            That is a whole different question actually. There is the script command for saving sessions of work.
            – Rui F Ribeiro
            2 days ago











          • script is what I can use, thanx!
            – Alexei Martianov
            2 days ago












          up vote
          2
          down vote










          up vote
          2
          down vote









          apt has been designed historically with interactive command-line use in mind, hence the coded warning, which has been done on purpose in/by apt and not by the shell.



          However, apt is not necessarily parsing the command line; the shell has already done that job by the time it calls apt. What apt is doing is detecting that the stdout stream has been changed/redirected.



          As for using apt in scripts, you have got the similar older command apt-get which does does more or less the same thing, and does not give that warning when stdout is redirected.



          TLDR Is not the shell writing the error message in stderr, it is the apt command.



          The fact that you are able to capture the apt stderr output in the shell is an artifact of Unix being a multitasking OS, and does not mean it is the shell producing that output.



          PS. Doing an strace at the command, it can be seen apt writing that message:



          strace apt get install bash > a
          ....
          write(2, "n", 1
          ) = 1
          write(2, "WARNING: ", 9WARNING: ) = 9
          write(2, "apt", 3apt) = 3
          write(2, " ", 1 ) = 1
          write(2, "does not have a stable CLI inter"..., 38does not have a stable CLI interface. ) = 38
          write(2, "Use with caution in scripts.", 28Use with caution in scripts.) = 28
          write(2, "n", 1
          ) = 1
          write(2, "n", 1
          ) = 1





          share|improve this answer















          apt has been designed historically with interactive command-line use in mind, hence the coded warning, which has been done on purpose in/by apt and not by the shell.



          However, apt is not necessarily parsing the command line; the shell has already done that job by the time it calls apt. What apt is doing is detecting that the stdout stream has been changed/redirected.



          As for using apt in scripts, you have got the similar older command apt-get which does does more or less the same thing, and does not give that warning when stdout is redirected.



          TLDR Is not the shell writing the error message in stderr, it is the apt command.



          The fact that you are able to capture the apt stderr output in the shell is an artifact of Unix being a multitasking OS, and does not mean it is the shell producing that output.



          PS. Doing an strace at the command, it can be seen apt writing that message:



          strace apt get install bash > a
          ....
          write(2, "n", 1
          ) = 1
          write(2, "WARNING: ", 9WARNING: ) = 9
          write(2, "apt", 3apt) = 3
          write(2, " ", 1 ) = 1
          write(2, "does not have a stable CLI inter"..., 38does not have a stable CLI interface. ) = 38
          write(2, "Use with caution in scripts.", 28Use with caution in scripts.) = 28
          write(2, "n", 1
          ) = 1
          write(2, "n", 1
          ) = 1






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited 2 days ago


























          answered 2 days ago









          Rui F Ribeiro

          33.3k1167112




          33.3k1167112











          • Is there any way to prevent e.g. apt from detecting redirection?
            – Alexei Martianov
            2 days ago






          • 1




            The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
            – Rui F Ribeiro
            2 days ago











          • What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
            – Alexei Martianov
            2 days ago






          • 1




            That is a whole different question actually. There is the script command for saving sessions of work.
            – Rui F Ribeiro
            2 days ago











          • script is what I can use, thanx!
            – Alexei Martianov
            2 days ago
















          • Is there any way to prevent e.g. apt from detecting redirection?
            – Alexei Martianov
            2 days ago






          • 1




            The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
            – Rui F Ribeiro
            2 days ago











          • What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
            – Alexei Martianov
            2 days ago






          • 1




            That is a whole different question actually. There is the script command for saving sessions of work.
            – Rui F Ribeiro
            2 days ago











          • script is what I can use, thanx!
            – Alexei Martianov
            2 days ago















          Is there any way to prevent e.g. apt from detecting redirection?
          – Alexei Martianov
          2 days ago




          Is there any way to prevent e.g. apt from detecting redirection?
          – Alexei Martianov
          2 days ago




          1




          1




          The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
          – Rui F Ribeiro
          2 days ago





          The canonical way is using the equivalent tools like apt-get and apt-cache. No switch/option to disable that behaviour that I know of.
          – Rui F Ribeiro
          2 days ago













          What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
          – Alexei Martianov
          2 days ago




          What bothers me is not of cause that single additional phrase from apt, but the whole thing that when I see a long output in shell, I'd like to store it, do text search later, but cannot save it 100% the way it displays.
          – Alexei Martianov
          2 days ago




          1




          1




          That is a whole different question actually. There is the script command for saving sessions of work.
          – Rui F Ribeiro
          2 days ago





          That is a whole different question actually. There is the script command for saving sessions of work.
          – Rui F Ribeiro
          2 days ago













          script is what I can use, thanx!
          – Alexei Martianov
          2 days ago




          script is what I can use, thanx!
          – Alexei Martianov
          2 days ago












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460503%2fredirecting-streams-in-bash-shell-how-to-make-unconditional-on-the-rest-of-she%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?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?