0

I have a variable that contains an IP address.

ip=192.165.12.30 

How can I replace the last octet with 0 so that it becomes as below?

ip=192.168.12.0
Toto
  • 89,455
  • 62
  • 89
  • 125
lystack
  • 41
  • 4

1 Answers1

3

You can use a parameter expansion:

$ ip=${ip%.*}.0
$ echo "$ip"
192.165.12.0
oguz ismail
  • 1
  • 16
  • 47
  • 69
Alfred456654
  • 195
  • 10