Hi, I don't know if I got what you want. I think it is after giving an interface name the script saves this name and the associated mac address. Is that true?
Here is an example of a script that does that.
Code:
#!/bin/bash
ifconfig -a |cut -f1 -d' '|grep -v '^$' > /tmp/net.$$ # Put all inet names in a tmp file.
echo -n "Choose your device:"
read device
grep -q "$device" /tmp/net.$$ #Test if there is such a device
test1=$?;
if [ $test1 -eq 0 ];then
ifconfig $device |grep -q HW # Test if this device has some Hardware address
test2=$?
if [ $test2 -eq 0 ];then
mac=`ifconfig $device |grep HW|cut -f2 -d'W'` # Get the mac
echo "The mac address of the interface $device is $mac"
else
echo The device $device has no mac address
fi
else
echo "There is no such interface \"$device\"" >&2 #Send it to the error output
rm -f /tmp/net.$$ # removes the file before exit
exit 1
fi
rm -f /tmp/net.$$ # removes the file
Some corrections about your script:
IN
Code:
intlist=ifconfig |grep HWaddr
the command must be between the accent `
Code:
intlist=`ifconfig |grep HWaddr`
or
Code:
intlist=$(ifconfig |grep HWaddr)
also works