0

Strange thing I have here, when apt is locked by something. Respectively, the error codes don't match up. apt update seems to always return success 0, whereas apt-get update returns a proper error code.

vlastimil@vb-nb-mint ~/Development/bash $ sudo apt-get update
Reading package lists... Done
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

vlastimil@vb-nb-mint ~/Development/bash $ echo $?
100

vlastimil@vb-nb-mint ~/Development/bash $ sudo apt update
Reading package lists... Done
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

vlastimil@vb-nb-mint ~/Development/bash $ echo $?
0

apt's location:

vlastimil@vb-nb-mint ~/Development/bash $ which apt
/usr/local/bin/apt

apt's version:

vlastimil@vb-nb-mint ~/Development/bash $ apt-show-versions apt
apt:amd64/xenial-updates 1.2.12~ubuntu16.04.1 uptodate

I originally wanted to use apt for the manual upgrade script, but this changes the situation. Does someone understand error codes and such in order to help me with this?

1

This is apparently intentional, see #778357: an exit code of 0 indicates success or a transient error, anything else indicates a permanent error.

As indicated in the apt manual page though:

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.

So you shouldn't use apt in scripts.

(It's odd that you have apt in /usr/local/bin; given that you have an up-to-date apt package installed, you probably have it in /usr/bin too!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.