apt gives “Unstable CLI Interface” warning












23














I am writing a script that needs to read a file containing information of a package for which I wrote this line



apt show $PACKAGE_NAME > pack_info.txt


However this doesn't creates the pack_info.txt file and always gives this Warning :




WARNING : apt does not have a stable CLI interface. Use with caution in scripts.




For the time being I tried redirecting both STDOUT & STDERR using &> and it worked out to give a file pack_info.txt that we need.



I also tried getting contents from dpkg and that also worked :



dpkg -s $PACKAGE_NAME > pack_info.txt


What is good that it neither shows a warning nor an error.



What is bad that we don't want to use dpkg and only want STDOUT of apt to redirect to file.



So, I have three Questions to ask :




  1. What do we exactly mean by Stable CLI Interface ?

  2. How to safely and error-free use such commands in scripts ?
    [please care to explain with example]

  3. Is there a way to only and only redirect STDOUT of apt show to a file ?










share|improve this question





























    23














    I am writing a script that needs to read a file containing information of a package for which I wrote this line



    apt show $PACKAGE_NAME > pack_info.txt


    However this doesn't creates the pack_info.txt file and always gives this Warning :




    WARNING : apt does not have a stable CLI interface. Use with caution in scripts.




    For the time being I tried redirecting both STDOUT & STDERR using &> and it worked out to give a file pack_info.txt that we need.



    I also tried getting contents from dpkg and that also worked :



    dpkg -s $PACKAGE_NAME > pack_info.txt


    What is good that it neither shows a warning nor an error.



    What is bad that we don't want to use dpkg and only want STDOUT of apt to redirect to file.



    So, I have three Questions to ask :




    1. What do we exactly mean by Stable CLI Interface ?

    2. How to safely and error-free use such commands in scripts ?
      [please care to explain with example]

    3. Is there a way to only and only redirect STDOUT of apt show to a file ?










    share|improve this question



























      23












      23








      23


      6





      I am writing a script that needs to read a file containing information of a package for which I wrote this line



      apt show $PACKAGE_NAME > pack_info.txt


      However this doesn't creates the pack_info.txt file and always gives this Warning :




      WARNING : apt does not have a stable CLI interface. Use with caution in scripts.




      For the time being I tried redirecting both STDOUT & STDERR using &> and it worked out to give a file pack_info.txt that we need.



      I also tried getting contents from dpkg and that also worked :



      dpkg -s $PACKAGE_NAME > pack_info.txt


      What is good that it neither shows a warning nor an error.



      What is bad that we don't want to use dpkg and only want STDOUT of apt to redirect to file.



      So, I have three Questions to ask :




      1. What do we exactly mean by Stable CLI Interface ?

      2. How to safely and error-free use such commands in scripts ?
        [please care to explain with example]

      3. Is there a way to only and only redirect STDOUT of apt show to a file ?










      share|improve this question















      I am writing a script that needs to read a file containing information of a package for which I wrote this line



      apt show $PACKAGE_NAME > pack_info.txt


      However this doesn't creates the pack_info.txt file and always gives this Warning :




      WARNING : apt does not have a stable CLI interface. Use with caution in scripts.




      For the time being I tried redirecting both STDOUT & STDERR using &> and it worked out to give a file pack_info.txt that we need.



      I also tried getting contents from dpkg and that also worked :



      dpkg -s $PACKAGE_NAME > pack_info.txt


      What is good that it neither shows a warning nor an error.



      What is bad that we don't want to use dpkg and only want STDOUT of apt to redirect to file.



      So, I have three Questions to ask :




      1. What do we exactly mean by Stable CLI Interface ?

      2. How to safely and error-free use such commands in scripts ?
        [please care to explain with example]

      3. Is there a way to only and only redirect STDOUT of apt show to a file ?







      command-line apt package-management






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '17 at 15:27









      dessert

      22k56197




      22k56197










      asked Dec 30 '17 at 14:28









      C0deDaedalus

      3262416




      3262416






















          1 Answer
          1






          active

          oldest

          votes


















          40














          apt is for the terminal and gives beautiful output while apt-get and apt-cache are for scripts and give stable, parseable output. The script equivalent of your apt show command therefore is:



          apt-cache show $PACKAGE_NAME >pack_info.txt




          Now to answer your questions one by one:




          What do we exactly mean by Stable CLI Interface?




          apt's output is not well useable in scripts. For example, apt install (compared to apt-get install) displays a progress bar that's useless for scripts and can throw errors when the output is parsed. apt show firefox shows a hint for an additional record, which is also totally useless in a script, you want it to simply output every record there – that's what apt-cache show firefox does. Let's see what man apt has to say about that:




          The apt(8) commandline is designed as an end-user tool and it may
          change behavior between versions. While it
          tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for
          interactive use.



          All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well. apt(8)
          just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you
          should prefer using these commands (potentially with some additional options enabled) in your scripts as they
          keep backward compatibility as much as possible.







          How to safely and error-free use such commands in scripts?




          Just use apt-get or apt-cache respectively instead of plain apt. :) See this answer for a list of equivalents.






          Is there a way to only and only redirect STDOUT of apt show to a file?




          You did that correctly already: >file or 1>file redirects stdout, 2>file redirects stderr and &>file redirects both to file.






          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/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%2faskubuntu.com%2fquestions%2f990823%2fapt-gives-unstable-cli-interface-warning%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









            40














            apt is for the terminal and gives beautiful output while apt-get and apt-cache are for scripts and give stable, parseable output. The script equivalent of your apt show command therefore is:



            apt-cache show $PACKAGE_NAME >pack_info.txt




            Now to answer your questions one by one:




            What do we exactly mean by Stable CLI Interface?




            apt's output is not well useable in scripts. For example, apt install (compared to apt-get install) displays a progress bar that's useless for scripts and can throw errors when the output is parsed. apt show firefox shows a hint for an additional record, which is also totally useless in a script, you want it to simply output every record there – that's what apt-cache show firefox does. Let's see what man apt has to say about that:




            The apt(8) commandline is designed as an end-user tool and it may
            change behavior between versions. While it
            tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for
            interactive use.



            All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well. apt(8)
            just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you
            should prefer using these commands (potentially with some additional options enabled) in your scripts as they
            keep backward compatibility as much as possible.







            How to safely and error-free use such commands in scripts?




            Just use apt-get or apt-cache respectively instead of plain apt. :) See this answer for a list of equivalents.






            Is there a way to only and only redirect STDOUT of apt show to a file?




            You did that correctly already: >file or 1>file redirects stdout, 2>file redirects stderr and &>file redirects both to file.






            share|improve this answer




























              40














              apt is for the terminal and gives beautiful output while apt-get and apt-cache are for scripts and give stable, parseable output. The script equivalent of your apt show command therefore is:



              apt-cache show $PACKAGE_NAME >pack_info.txt




              Now to answer your questions one by one:




              What do we exactly mean by Stable CLI Interface?




              apt's output is not well useable in scripts. For example, apt install (compared to apt-get install) displays a progress bar that's useless for scripts and can throw errors when the output is parsed. apt show firefox shows a hint for an additional record, which is also totally useless in a script, you want it to simply output every record there – that's what apt-cache show firefox does. Let's see what man apt has to say about that:




              The apt(8) commandline is designed as an end-user tool and it may
              change behavior between versions. While it
              tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for
              interactive use.



              All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well. apt(8)
              just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you
              should prefer using these commands (potentially with some additional options enabled) in your scripts as they
              keep backward compatibility as much as possible.







              How to safely and error-free use such commands in scripts?




              Just use apt-get or apt-cache respectively instead of plain apt. :) See this answer for a list of equivalents.






              Is there a way to only and only redirect STDOUT of apt show to a file?




              You did that correctly already: >file or 1>file redirects stdout, 2>file redirects stderr and &>file redirects both to file.






              share|improve this answer


























                40












                40








                40






                apt is for the terminal and gives beautiful output while apt-get and apt-cache are for scripts and give stable, parseable output. The script equivalent of your apt show command therefore is:



                apt-cache show $PACKAGE_NAME >pack_info.txt




                Now to answer your questions one by one:




                What do we exactly mean by Stable CLI Interface?




                apt's output is not well useable in scripts. For example, apt install (compared to apt-get install) displays a progress bar that's useless for scripts and can throw errors when the output is parsed. apt show firefox shows a hint for an additional record, which is also totally useless in a script, you want it to simply output every record there – that's what apt-cache show firefox does. Let's see what man apt has to say about that:




                The apt(8) commandline is designed as an end-user tool and it may
                change behavior between versions. While it
                tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for
                interactive use.



                All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well. apt(8)
                just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you
                should prefer using these commands (potentially with some additional options enabled) in your scripts as they
                keep backward compatibility as much as possible.







                How to safely and error-free use such commands in scripts?




                Just use apt-get or apt-cache respectively instead of plain apt. :) See this answer for a list of equivalents.






                Is there a way to only and only redirect STDOUT of apt show to a file?




                You did that correctly already: >file or 1>file redirects stdout, 2>file redirects stderr and &>file redirects both to file.






                share|improve this answer














                apt is for the terminal and gives beautiful output while apt-get and apt-cache are for scripts and give stable, parseable output. The script equivalent of your apt show command therefore is:



                apt-cache show $PACKAGE_NAME >pack_info.txt




                Now to answer your questions one by one:




                What do we exactly mean by Stable CLI Interface?




                apt's output is not well useable in scripts. For example, apt install (compared to apt-get install) displays a progress bar that's useless for scripts and can throw errors when the output is parsed. apt show firefox shows a hint for an additional record, which is also totally useless in a script, you want it to simply output every record there – that's what apt-cache show firefox does. Let's see what man apt has to say about that:




                The apt(8) commandline is designed as an end-user tool and it may
                change behavior between versions. While it
                tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for
                interactive use.



                All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well. apt(8)
                just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you
                should prefer using these commands (potentially with some additional options enabled) in your scripts as they
                keep backward compatibility as much as possible.







                How to safely and error-free use such commands in scripts?




                Just use apt-get or apt-cache respectively instead of plain apt. :) See this answer for a list of equivalents.






                Is there a way to only and only redirect STDOUT of apt show to a file?




                You did that correctly already: >file or 1>file redirects stdout, 2>file redirects stderr and &>file redirects both to file.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 23 at 19:43

























                answered Dec 30 '17 at 15:15









                dessert

                22k56197




                22k56197






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f990823%2fapt-gives-unstable-cli-interface-warning%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

                    數位音樂下載

                    格利澤436b

                    When can things happen in Etherscan, such as the picture below?