I am writing my first bash script (and first LQ post) and need some help. I am trying to have a user enter data into a defined variable and then display that variable in formatted output. I also want to omit output if the user does not enter data into the variable. In my testing, I have used the Enter Key when the scripts asks for data that I want to leave blank.
Most of this is working well. However, my script displays an error in the output when there is data or not in the variable. So my If test needs some help. I have included my code.
Code:
SRC_NET_2=1
echo "Enter the second source network with subnet mask (No CIDR) : "
read SRC_NET_2
multi-source_pat(){
if [ $SRC_NET_2 -ne "1" ]
then echo " access-list acl_pat_$SITE_ID extended permit ip $SRC_NET_2 any"
elif [ $SRC_NET_2 -eq "" ] ; then echo ""
fi
}
here is the error with a value entered into the variable
./msb.sh: line 113: [: too many arguments
./msb.sh: line 115: [: too many arguments
here is the error with the enter key used to skip data entry
./msb.sh: line 113: [: -ne: unary operator expected
./msb.sh: line 115: [: -eq: unary operator expected