7

When using apt from "dumb" terminal (this is a code word for Emacs), it produces many lines of garbage output (it probably tries to display progress, but it doesn't work on this kind of terminal).

The same happens if I try to save this information to a file, which blows up the logs contributing no useful information.

Thus, is there a way to prevent apt from producing garbled output?

I've seen the SO question asking for the opposite, and I think that this behavior is new. So, if the version is important, it is: apt 1.4.6 (amd64)

wvxvw
  • 358
  • As you do not want the output, redirect to /dev/null sudo apt install -y foo > /dev/null 2> /dev/null – Panther Sep 17 '17 at 14:17
  • 2
  • @bodhi.zazen who says I don't want the output? I don't want output garbled by apt trying to display the progress of the download. – wvxvw Sep 18 '17 at 05:24
  • I guess you need to be more specific on what you want and dont want and either change to apt-get for example https://askubuntu.com/questions/258219/how-do-i-make-apt-get-install-less-noisy or figure out what the "many lines of garbage output" is exactly and configure apt - https://mvogt.wordpress.com/2014/04/04/apt-1-0/ and the man pages http://manpages.ubuntu.com/manpages/zesty/man8/apt.8.html and http://manpages.ubuntu.com/manpages/zesty/man5/apt.conf.5.html – Panther Sep 18 '17 at 13:45

2 Answers2

10

For the use in scripts, dumb terminals etc. there is apt-get, see man apt:

apt provides a high-level commandline interface for the package management system. It is intended as an end user interface and enables some options better suited for interactive usage by default compared to more specialized APT tools like apt-get(8) and apt-cache(8).

SCRIPT USAGE AND DIFFERENCES FROM OTHER APT TOOLS

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.

dessert
  • 39,982
  • So, basically it says that it is useless inside Emacs? What a nice tool... – wvxvw Sep 17 '17 at 14:13
  • 2
    @wvxvw It is a very nice tool, just that Emacs doesn't seem to keep up with it. :) If you want fancy output for your package management try aptitude – however I don't know how far Emacs can deal with it. – dessert Sep 17 '17 at 14:26
  • Well, not exactly. Emacs uses only standard VT100 and ISO codes, while other program developers often rely on all sorts of extensions made popular by various terminals to be universal. This is why the environment variable TERM exists - programs sending output to console should respect it. apt does half the job: it checks this variable, discovers that the terminal doesn't have all the functions it wants, but only removes some of them (starts using readline instead of a fancy curses dialog windows). This is just bad programming on the side of apt. – wvxvw Sep 18 '17 at 05:22
  • @wvxvw Respect, you did the research! I don't have so much insight, but if that's true please file a bug on https://bugs.launchpad.net/ubuntu/+source/apt and let the devs know. – dessert Sep 18 '17 at 05:27
6

There are more differences between apt and apt-get than the fancy progress bar, so you might want to turn that off while keeping all the other differences:

sudo apt -o Dpkg::Progress-Fancy=0 action args...

Some sources show Dpkg::Progress-Fancy="0", which is fine but equivalent to Dpkg::Progress-Fancy=0 since shells don't expand 0 anyway and the quotes are simply removed.

You probably don't want to change this setting globally because when you run apt outside of Emacs you will likely want the fancy progress bar. However, you could make a shorter command that achieves the same goal, such as with an eshell alias.

Eliah Kagan
  • 117,780