netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* iproute2 / question: returncode when query a match
@ 2015-06-04  8:16 Bastian Bittorf
       [not found] ` <20150614162616.GA25952@angus-think.lan>
  0 siblings, 1 reply; 3+ messages in thread
From: Bastian Bittorf @ 2015-06-04  8:16 UTC (permalink / raw)
  To: netdev

when executing e.g.:

root@box:~ ip route list exact '0.0.0.0/0'
default via 10.63.42.125 dev eth0.2  metric 2 onlink 
root@box:~ echo $?
0
root@box:~ ip route list exact '0.0.0.0/8'
root@box:~ echo $?
0

i expected an RC of != 0 when there is no match.
is this by design?

root@box:~ ip -V
ip utility, iproute2-ss4.0.0-1-openwrt

bye, bastian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: iproute2 / question: returncode when query a match
       [not found] ` <20150614162616.GA25952@angus-think.lan>
@ 2015-06-26  7:31   ` Bastian Bittorf
  2015-06-26 22:30     ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Bastian Bittorf @ 2015-06-26  7:31 UTC (permalink / raw)
  To: netdev, Vadim Kochan

* Vadim Kochan <vadim4j@gmail.com> [15.06.2015 18:36]:
> > root@box:~ ip route list exact '0.0.0.0/8'
> > root@box:~ echo $?
> > 0
> > 
> > i expected an RC of != 0 when there is no match.
> > is this by design?
> > 
> > root@box:~ ip -V
> > ip utility, iproute2-ss4.0.0-1-openwrt
> 
> I think that RC != 0 only in case error happened, but may be its good
> idea to add such behaviour or add option to consider ret code
> if there is no results ?

ofcourse this is only useful for scripting:

# ip route list exact '0.0.0.0/8' || do_some_action

instead of the now used construct:
# [ -n "$( ip route list exact '0.0.0.0/8' )" ] || do_some_action

i'am sure there are other queries, where this also
makes sense. there are 2 possible ways for implementing this IMHO:

introduce a commandlineswitch like --pedantic
or just always throw an error 1 when there is no match like this:

root@box:~ echo foo | grep bar
root@box:~ echo $?
1

more opinions about that?

bye, bastian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: iproute2 / question: returncode when query a match
  2015-06-26  7:31   ` Bastian Bittorf
@ 2015-06-26 22:30     ` Stephen Hemminger
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2015-06-26 22:30 UTC (permalink / raw)
  To: Bastian Bittorf; +Cc: netdev, Vadim Kochan

On Fri, 26 Jun 2015 09:31:45 +0200
Bastian Bittorf <bittorf@bluebottle.com> wrote:

> * Vadim Kochan <vadim4j@gmail.com> [15.06.2015 18:36]:
> > > root@box:~ ip route list exact '0.0.0.0/8'
> > > root@box:~ echo $?
> > > 0
> > > 
> > > i expected an RC of != 0 when there is no match.
> > > is this by design?
> > > 
> > > root@box:~ ip -V
> > > ip utility, iproute2-ss4.0.0-1-openwrt
> > 
> > I think that RC != 0 only in case error happened, but may be its good
> > idea to add such behaviour or add option to consider ret code
> > if there is no results ?
> 
> ofcourse this is only useful for scripting:
> 
> # ip route list exact '0.0.0.0/8' || do_some_action
> 
> instead of the now used construct:
> # [ -n "$( ip route list exact '0.0.0.0/8' )" ] || do_some_action
> 
> i'am sure there are other queries, where this also
> makes sense. there are 2 possible ways for implementing this IMHO:
> 
> introduce a commandlineswitch like --pedantic
> or just always throw an error 1 when there is no match like this:
> 
> root@box:~ echo foo | grep bar
> root@box:~ echo $?
> 1
> 
> more opinions about that?
> 
> bye, bastian

Exit codes for ip route are already used to handle errors.
See current man page.

If you want to handle both errors and no match, the scripting tricks
to look for empty output are better.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-26 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-04  8:16 iproute2 / question: returncode when query a match Bastian Bittorf
     [not found] ` <20150614162616.GA25952@angus-think.lan>
2015-06-26  7:31   ` Bastian Bittorf
2015-06-26 22:30     ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).