0

I am running a bash script :

#!/bin/bash
touch archlinux_log.txt
touch packages_not_in_archlinux.txt

while read line; do
if pacman -Q --info $line ; then

  pacman -Q --info $line >> archlinux_log.txt

else echo "No Package info for $line" $line >> packages_not_in_archlinux.txt fi done<"$1"

However, a very peculiar problem that I am facing here is that the script always stops at a particular package name called dirmngr and displays the following message :

dirmngr[10701.0]: permanently loaded certificates: 141
dirmngr[10701.0]:     runtime cached certificates: 0
dirmngr[10701.0]:            trusted certificates: 141 (141,0,0,0)

I have ran the same script in Debian and Fedora and encountered no problems as such. All packages were scanned through. Any hints why this is happening with archlinux? Help will be deeply appreciated. Thanks!

MathMan
  • 181

1 Answers1

3

The following line in your script will execute whatever is in $line and append the output to packages_not_in_archlinux.txt:

$line >> packages_not_in_archlinux.txt

If $line expands to dirmngr, then that is the command that would be run at that point in the script.

You might have wanted to store the string $line in the output file instead:

printf '%s\n' "$line" >>packages_not_in_archlinux.txt

The whole script, with proper quoting of variables and avoiding to run pacman twice:

#!/bin/sh

tmpfile=$(mktemp)

while IFS= read -r package; do
if pacman -Q --info "$package" >"$tmpfile" then cat "$tmpfile" >>archlinux_log.txt else printf 'No package info for %s\n' "$package" printf '%s\n' "$package" >>packages_not_in_archlinux.txt fi done <"$1"

rm -f "$tmpfile"

Related:

Kusalananda
  • 333,661