~alpine/devel

4 4

[alpine-devel] APK Tools: exit code for list applet?

Details
Message ID
<ed8b88f8-6185-6a72-cf46-1886ba2e3844@Wilcox-Tech.com>
Sender timestamp
1561435576
DKIM signature
missing
Download raw message
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/
Paul Bredbury <brebs@sent.com>
Details
Message ID
<ed6abf6913e7f47a8291dd8fd6bd9d5d675ee161.camel@sent.com>
In-Reply-To
<ed8b88f8-6185-6a72-cf46-1886ba2e3844@Wilcox-Tech.com> (view parent)
Sender timestamp
1561471244
DKIM signature
missing
Download raw message
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
---
Details
Message ID
<5aebf794-e1d7-9064-9885-5483b32a460a@adelielinux.org>
In-Reply-To
<ed6abf6913e7f47a8291dd8fd6bd9d5d675ee161.camel@sent.com> (view parent)
Sender timestamp
1561507469
DKIM signature
missing
Download raw message
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
Details
Message ID
<BV38JPLIZDP0.22O9Z08SKGU1Q@homura>
In-Reply-To
<5aebf794-e1d7-9064-9885-5483b32a460a@adelielinux.org> (view parent)
Sender timestamp
1561508447
DKIM signature
missing
Download raw message
#!/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
---
Roi Greenberg <roigr@checkpoint.com>
Details
Message ID
<1D9ECE54DC082549B6CDE5C6261F0C3C01797AC8D2@IL-EX10.ad.checkpoint.com>
In-Reply-To
<BV38JPLIZDP0.22O9Z08SKGU1Q@homura> (view parent)
Sender timestamp
1561531265
DKIM signature
missing
Download raw message
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
---
Reply to thread Export thread (mbox)