0

I'm trying to do a script in Bash to add some firewall rules.

The variable I'm passing isn't working, I guess I'm doing the substitution wrong.

firewall-cmd --add-rich-rule='rule family="ipv4" source address="$IP/32" port port=10000 protocol=tcp accept'

Returns

Error: INVALID_ADDR: $IP/32

What's wrong here, and how do I fix it?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Dominique
  • 33
  • 3

1 Answers1

0

You are single-quoting the entire string, so you are passing the literal string $IP. You can break out of the single quotes temporarily by adding a closing single quote before the variable and a new single quote after it.

firewall-cmd --add-rich-rule='rule family="ipv4" source address="'$IP'/32" port port=10000 protocol=tcp accept'
tripleee
  • 175,061
  • 34
  • 275
  • 318
Nitish
  • 597
  • 1
  • 4
  • 9