Hello there,
I noticed that when `apk list` does not return any results, it still
exits with return code 0. I feel it would be useful for scripts and
automation for it to return code 1 if there are no results.
This could also be used for something like:
apk list -u && printf "Updates are available\n"
and various other things.
If this is something that is desired, I would be more than happy to try
my hand at a patch.
Best,
--arw
--
A. Wilcox (awilfox)
Open-source programmer (C, C++, Python)
https://code.foxkit.us/u/awilfox/
On Mon, 2019-06-24 at 23:06 -0500, A. Wilcox wrote:
> I noticed that when `apk list` does not return any results, it still> exits with return code 0. I feel it would be useful for scripts and> automation for it to return code 1 if there are no results.
An empty list is not an error. Being unable to produce the list, would be an actual error. Scripts can just check whether the list is empty.
---
Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org
Help: alpine-devel+help@lists.alpinelinux.org
---
On 06/25/19 09:00, Paul Bredbury wrote:
> On Mon, 2019-06-24 at 23:06 -0500, A. Wilcox wrote:>> I noticed that when `apk list` does not return any results, it>> still exits with return code 0. I feel it would be useful for>> scripts and automation for it to return code 1 if there are no>> results.> > An empty list is not an error. Being unable to produce the list,> would be an actual error. Scripts can just check whether the list is> empty.>
I'm unaware of any portable POSIX shell construct to do that, at least
not without invoking a cavalcade of other processes for what could be so
much simpler.
But okay.
--arw
--
A. Wilcox (awilfox)
Project Lead, Adélie Linux
https://www.adelielinux.org
An easy way to do what you want:
test "$(apk list -u)" && printf "Updates are available\n"
-----Original Message-----
From: Drew DeVault [mailto:sir@cmpwn.com]
Sent: Wednesday, June 26, 2019 03:21
To: A. Wilcox; alpine-devel@lists.alpinelinux.org
Subject: Re: [alpine-devel] APK Tools: exit code for list applet?
#!/bin/sh -e
results=0
IFS="(printf '\n\b')"
for line in (apk list "$@")
do
results=$((results+1))
done
echo "results: $results"
---
Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org
Help: alpine-devel+help@lists.alpinelinux.org
---