I have a question on how I'm adding arguments when executing a shell script.
I have a simple script which helps me block ip ranges:
if [ ! $3 ] then echo "usage ~/block_ip.sh (DROP/ACCEPT) '0.0.0.0' 'amsterdam'" exit 1 fi echo "adding $3" sudo iptables -I INPUT -s $2 -j $1 -m comment --comment "$3"
If I execute this without arguments the output is as expected:
~$ ./block_ip.sh usage ~/block_ip.sh (DROP/ACCEPT) '0.0.0.0' 'amsterdam'
However the spaces seem to be the cause of the unexpected output of "binary operator expected":
~$ ./block_ip.sh DROP '188.8.131.52/8' 'south brisbane qld' ./block_ip.sh: line 1: [: brisbane: binary operator expected adding south brisbane au
But then it adds it despite the unexpected output:
Chain INPUT (policy ACCEPT) num target prot opt source destination 1 DROP all -- 184.108.40.206/8 anywhere /* south brisbane au */
If this is a quoting issue, how do I form the arguments (without using backslashes to escape the spaces)? Of course, I expect I may need a change to the script, that is an acceptable solution, too.