[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

if statement in bash

Alway had problems with If statements

This will tell me if I have a default route
netstat -r | grep default

Now if I want to say "yeh" if i have a default route, can someone fix this

if [[     netstat -r | grep default    ]] then echo "yeh"  fi
0
TIMFOX123
Asked:
TIMFOX123
3 Solutions
 
pony10usCommented:
if [ netstat -r | grep default ]; then
               echo yeh
            fi
0
 
woolmilkporcCommented:
grep -q

to get rid of grep's output.
0
 
arnoldCommented:
netstat -n | grep default 2>&1 >/dev/null && echo yeh
0
 
woolmilkporcCommented:
if netstat -r | grep -q default ; then echo yeh; fi
0
 
TIMFOX123Author Commented:
thanks porky
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now