# need a quick basic shell script help

**URL:** <https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024>\
**Category:** Shell Programming and Scripting\
**Created:** [November 22, 2007, 7:09am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024 "2007-11-22T07:09:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eb222](https://community.unix.com/letter_avatar/eb222/32/6_22734026db12803ebb3e059622ac3534.png) [@eb222](https://community.unix.com/u/eb222)\
**Post date:** [November 22, 2007, 7:09am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/1 "2007-11-22T07:09:33Z")

</div>

im trying to run the below if command

ifconfig -a |grep 10.100.120.21

gives me below output  
inet addr:10.100.120.21 Bcast:10.100.120.255 Mask:255.255.255.0

i just want a basic shell which says if above exists then continue

how would i do this?

---

<div class="post-metadata">

**Author:** ![porter](https://community.unix.com/letter_avatar/porter/32/6_22734026db12803ebb3e059622ac3534.png) [@porter](https://community.unix.com/u/porter)\
**Post date:** [November 22, 2007, 7:14am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/2 "2007-11-22T07:14:35Z")

</div>

```nohighlight
#!/bin/sh

ifconfig -a |grep 10.100.120.21 
if test "$?" = "0"
then
     echo I found the address
else
     echo I did not find the address
fi

```

---

<div class="post-metadata">

**Author:** ![Cameron](https://community.unix.com/user_avatar/community.unix.com/cameron/32/41_2.png) [@Cameron](https://community.unix.com/u/Cameron)\
**Post date:** [November 22, 2007, 7:19am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/3 "2007-11-22T07:19:09Z")

</div>

Hi Porter,  
What OS is ` ifconfig -a ` used in, doesn't work for HP-UX.

---

<div class="post-metadata">

**Author:** ![eb222](https://community.unix.com/letter_avatar/eb222/32/6_22734026db12803ebb3e059622ac3534.png) [@eb222](https://community.unix.com/u/eb222)\
**Post date:** [November 22, 2007, 7:41am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/4 "2007-11-22T07:41:42Z")

</div>

thanks that worked -ifconfig -a is used to find ethernet addresses

---

<div class="post-metadata">

**Author:** ![porter](https://community.unix.com/letter_avatar/porter/32/6_22734026db12803ebb3e059622ac3534.png) [@porter](https://community.unix.com/u/porter)\
**Post date:** [November 22, 2007, 7:53am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/5 "2007-11-22T07:53:01Z")

</div>

> [@cameron](#):
>
> Hi Porter,  
> What OS is ` ifconfig -a ` used in, doesn't work for HP-UX.

Solaris, NetBSD, Linux ... it's fairly common. It does the command for all interfaces.

---

<div class="post-metadata">

**Author:** ![Cameron](https://community.unix.com/user_avatar/community.unix.com/cameron/32/41_2.png) [@Cameron](https://community.unix.com/u/Cameron)\
**Post date:** [November 22, 2007, 7:56am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/6 "2007-11-22T07:56:12Z")

</div>

Cheers porter.  
Thought I was missing something there for a moment. 😉

---

<div class="post-metadata">

**Author:** ![grial](https://community.unix.com/user_avatar/community.unix.com/grial/32/379_2.png) [@grial](https://community.unix.com/u/grial)\
**Post date:** [November 22, 2007, 8:00am UTC](https://community.unix.com/t/need-a-quick-basic-shell-script-help/178024/7 "2007-11-22T08:00:07Z")

</div>

```nohighlight
[[! -z "$(ifconfig -a | grep 10.100.120.21)"]] && echo Exists

```

🙂
