You've actually got a couple of problems with that script. The major one is that ipconfig will output "\r" characters at the end of the line which stuffs up the calculation.
Another is that you're not allowing for multiple NICs, hence my "head -1"
addition. You'll need to select which NIC you want a little more intelligently.
And finally, I stripped out the leading space (actually all spaces) from the front of the IP address.
The following works for me:
#!/bin/bash
#set -x
function IPADDRESS {
((v = $4 - 2))
echo $1.$2.$3.$v
}
ADDRESS=$(ipconfig | grep Address | head -1 | cut -f2 -d: | sed 's/[ \r]//g')
echo $ADDRESS
IPADDRESS $ADDRESS
outputting:
192.168.91.7
192.168.91.5
Actually, my version output the following:
192.168.91.1
192.168.91.-1
so you'll need to watch out for that.
I'm no stranger to dummying up the output to impress/cajole management :-).
USEFUL SNIPPET:
The "set -x"
at the top of the script (when un-commented) is ideal for finding these sorts of errors. It outputs each line after all the substitutions but before executing, so that you can see exactly what's going on.