Query APT configuration to inspect specific options or create universal Debian utilities.

Query all APT configuration options

Query and display all APT configuration options.

$ apt-config dump 
APT "";
APT::Architecture "amd64";
APT::Build-Essential "";
APT::Build-Essential:: "build-essential";
APT::Install-Recommends "1";
APT::Install-Suggests "0";
Dir "/";
Dir::State "var/lib/apt";
Dir::State::lists "lists/";
Dir::State::cdroms "cdroms.list";
Dir::State::mirrors "mirrors/";
Dir::State::extended_states "extended_states";
Dir::State::status "/var/lib/dpkg/status";
Acquire::AllowInsecureRepositories "0";
Acquire::AllowWeakRepositories "0";
Acquire::AllowDowngradeToInsecureRepositories "0";
CommandLine::AsString "apt-config dump";

Query all APT configuration options and display cache settings.

$ apt-config dump | grep "^Dir\( \|::Cache\)"
Dir "/";
Dir::Cache "var/cache/apt";
Dir::Cache::archives "archives/";
Dir::Cache::srcpkgcache "srcpkgcache.bin";
Dir::Cache::pkgcache "pkgcache.bin";
Dir::Cache::Backup "backup/";

Use the specific format and additional utilities like grep and cut to query and display regular expressions matching packages that will not be automatically removed.

$ apt-config dump --no-empty --format '%f,%v%n' | grep NeverAutoRemove | grep -v  "^$" | cut -d, -f2 

Investigate the potential impact on the APT configuration.

$ diff  <(apt-config dump | grep -v CommandLine::AsString) <(apt-config -o APT::Install-Suggests=1 dump | grep -v CommandLine::AsString)
< APT::Install-Suggests "0";
> APT::Install-Suggests "1";
$ diff <(apt-config dump | grep -v CommandLine::AsString) <(apt-config -o Acquire::http::Proxy="" dump | grep -v CommandLine::AsString)
> Acquire::http "";
> Acquire::http::Proxy "";

Query individual APT configuration options

Query and display individual APT configuration options.

$ eval $(apt-config shell Dir Dir)
$ eval $(apt-config shell CacheDir Dir::Cache)
$ echo ${Dir}${CacheDir}

It is especially useful inside shell scripts to create universal configuration utilities.

# bash function
# return source list file path for provided name
function source_list_file_path() {
  local name dir etc src

  if [ -n "${1}" ]; then

    # set defaults

    # query configuration options
    eval $(apt-config shell dir Dir)
    eval $(apt-config shell etc Dir::Etc)
    eval $(apt-config shell src Dir::Etc::sourceparts)

    # return path for source list file
    echo "${dir}${etc}/${src}/${name}.list"
$ source_list_file_path "jenkins"

Alternatively, you can use APT configuration to store and query options to set up a custom application, but there are probably better ways to achieve this goal.

Read apt-config manual page.