Hello! Doing some spring cleaning of old iproute bug reports in Debian. Sorry for the very late reply. ;)
On Mon, Dec 21, 2009 at 03:26:34PM +0000, Paul Evans wrote: > I'm trying to test for the presence of a default route. Unfortunately I > can't just use > > if ip route show 0.0.0.0/0 >/dev/null; then > echo "Have default" > fi > > because 'ip route show' exits 0 regardless: > > $ ip route show 0.0.0.0/0 ; echo $? > default via 192.168.2.1 dev eth0 > 0 > > $ ip route show 0.0.4.0/1 ; echo $? > 0 > > Perhaps it could exit some non-zero status if no routes were found? You have a very straight forward use case here and at a quick glance I wanted to agree with you.... after thinking some more I no longer do. I guess this boils down to the definition of "failure". I think the iproute2 commands usually defines a failure as the kernel reporting a problem with any of the commands. With that definition of failure we don't have one here. Also, no matches to the given filter is available so none is printed is kind of expected behaviour. I think an equally good way to handle this would be to just pipe to grep here... if ip route show 1.2.3.0/24 | grep 1.2.3.0/24 > /dev/null ; then echo found else echo not found fi Unless you can convince me otherwise, I think I'll be closing this bug report soon. (On a related note though, I think it used to work to do something like "ip route show 1.2.3.4/32" and get the route that would pick that up, ie. "1.2.3.0/24" if you had such a route, or "default" otherwise...) -- Andreas Henriksson -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org