Referring from the print of the previous command

Hi,

I am a newbie in SHell Programming.
I want to ask something about referring the result of the previous command in Shell-Prog.

For example :
bnm@dsds~> ifconfig

eth0 Link encap:Ethernet HWaddr 00:0B:CD:85:A5:8A
inet addr:192.168.0.2 Bcast:192.168.0.225 Mask 255.255.255.0

bnm@dsds~> next command ???

My question is : What should i type as the next command ??? using
the if-statement below :
--------------
if [ HWaddr is equal to 00:0B:CD:85:A5 ]; then
.....
fi
--------------
so that it will refer to the HWaddr 00:0B:CD:85:A5 printed
as the result of the previous command ?

Thanks in advance.

Bob

There are many ways of doing what you want. Here is an example of one way

#!/usr/local/bin/bash

ifconfig eth0 > ifconfig.out
hwaddr=$(grep "HWaddr" ifconfig.out | cut -d " " -f 5)

if [ $hwaddr = "00:0B:CD:85:A5:8A" ]
then
    echo "match"
fi

Thank you for the answer, fpmurphy.
Could i know the other ways, please ? since i am avoiding writing the result into a file.
Then, what does "cut -d "" -f 5" mean ?

:slight_smile: