You are not logged in.
Hey guys,
I'm currently writing a small bash script to check if there are any updates for my packages installed from the AUR. For this I need to get an array from the output of
pacman -Qm
. I've tried this
packages=(`pacman -Qm`)
, but this isn't that what I've intended for.
I want to have an array like this
packages=("packagename version", "packagename version" ...)
Does anybody know the way, how to solve this problem?
Best regards,
the_metalgamer
Last edited by the_metalgamer (2013-02-23 22:24:11)
Blog - Github - Deviantart
Offline
┌─[Centurion ~]
└─╼ packages=(); IFS=\n; while read -r; do packages+=("$REPLY"); done < <(pacman -Qm)
┌─[Centurion ~]
└─╼ echo "${#packages}"
22
┌─[Centurion ~]
└─╼ echo "${packages[3]}"
aurvote 1.5-1
See Greg's Wiki for details...
Offline
Thank you very much indeed.
Best regards,
the_metalgamer
Blog - Github - Deviantart
Offline
IFS=\n
I don't believe that does what you think it does. It sets IFS to be the string '\n' and NOT a newline.
Try this
IFS=$'\n' packages=($(pacman -Qm))
Offline
IFS=\n
I don't believe that does what you think it does. It sets IFS to be the string '\n' and NOT a newline.
You are right, I should have quoted the newline. Oddly, the loop still reads the entries in using the newline as the separator; as the output shows...
Offline
Just to clarify this:
With the solution in post #2 the IFS variable will contain just an "n". So any package name containing an "n" will be cut into pieces.
$ echo ${packages[1]}
e emyli es3 1.2-1
The correct splitting is not caused by the IFS variable but by the read command which ALWAYS stops reading at a newline no matter what the IFS is set to. So there is no need to set the IFS variable to anything different and just use
packages=(); while read -r; do packages+=("$REPLY"); done < <(pacman -Qm)
Offline