2

I am trying to separate the ip/block address and place the ip in a variable and the block in another. This is what I have so far.

#!/bin/bash

ipblock="100.100.40.160/29"
block="$(basename $ipblock)"
#ipaddress="100.100.40.160"

echo "block=\"$block\""
#echo "address=\"$ipaddress\""

I need the ip address equation so that the results are ...

block="29"
address="100.100.40.160"
Curious Sam
  • 893
  • 1
  • 6
  • 26
  • I don't see how your link makes my question a duplicate. Somewhat same scenario but not duplicate. I could not use their answer to formulate an equation to give me the answer I was looking for. Thanks for trying. – Curious Sam Apr 23 '18 at 01:04

1 Answers1

0

I kept research the boards here and found something similar at https://stackoverflow.com/a/4170409/2186005 and it works well.

#!/bin/bash

ipblock="100.100.40.160/29"
block="$(basename $ipblock)"
ipaddress="${ipblock%/*}"

echo "block=\"$block\""
echo "address=\"$ipaddress\""

when I ran the script, I received the results I was initially looking for.

root@hills #/home # sh script.sh
block="29"
address="100.100.40.160"
Curious Sam
  • 893
  • 1
  • 6
  • 26