I am building a script to detect if IPSET exists.
#!/bin/bash
str=$(/usr/sbin/ipset test IPsetName 1.1.1.1)
echo "$str" #outputs blank line
if [[ $str = *"The set with the given name does not exist"* ]]; then
echo "IPsetName not found"
fi
When I run this script I get this output:
ipset v6.29: The set with the given name does not exist
then a blank line for echo "$str" and I don't see the expected output from the if statement.
How to store the ipset command output to the variable?
str=$(.... 2>&1)to capture that as well.str=$((/usr/sbin/ipset test IPsetName 1.1.1.1) 2>&1)(..). Juststr=$(/usr/sbin/ipset ... 2>&1)would work.