On 2021-01-28 08:07:51 -0500, Greg Wooledge wrote: > On Thu, Jan 28, 2021 at 02:26:47AM +0100, Vincent Lefevre wrote: > > print -r ${${(M)${(f)"$(aptitude show units)"}:#Version:*}#* } > > I have one major objection to this: how do you handle a package that > has more than one version available? > > unicorn:~$ apt-cache show firefox-esr | grep ^Version: > Version: 78.7.0esr-1~deb10u1 > Version: 78.5.0esr-1~deb10u1
The units package has 2 versions available: zira:~> apt-cache show units | grep "^Version:" Version: 2.21-1 Version: 2.18-1 but "aptitude show units" only returns one of them (the preferred one, I suppose). So, no issues with my code. In my previous message, I also gave the equivalent with apt-cache, by using the --no-all-versions option. [...] > One of the advantages of this version over the zsh version is that it > doesn't need to read the whole output of aptitude into memory all at > once. Note that with zsh, one can also do a process substitution. However, I would tend to say that process substitution is more complex and would have more overhead. At least there are more system calls with bash: zira:~> strace -f -o str.out bash -c 'v=$(date)' ; wc -l str.out 471 str.out zira:~> strace -f -o str.out bash -c ': < <(date)' ; wc -l str.out 535 str.out So I would say that command substitution is here more efficient. Not much difference with zsh, though: zira:~> strace -f -o str.out zsh -fc 'v=$(date)' ; wc -l str.out 725 str.out zira:~> strace -f -o str.out zsh -fc ': < <(date)' ; wc -l str.out 726 str.out -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)