I'm trying to run this simple script that succesfully run on CentOS but not on Ubuntu. The script start succesfully but fails to get into the if condition and straight moving to the else.
Is there any syntax error with the if loop? The idea is to get the content of filename output2.txt into a variable named value (is that command OK?) and check if subtext 512.00GB include in the text (in value)...
sudo msecli -L > output2.txt value=`cat output2.txt` check="512.00GB" #echo "$value" if [[ "$value" == *"$check"* ]]; then echo "The SSD is 512GB" sudo msecli -L >> output.txt sudo nvme delete-ns -n 1 /dev/nvme0 sudo nvme delete-ns -n 1 /dev/nvme1 sleep 1 sudo msecli -N -q 100 -n /dev/nvme0 -r sleep 1 sudo msecli -N -q 100 -n /dev/nvme1 -r sleep 2 sudo reboot else sudo msecli -L >> output.txt echo "***** The SSD is READY!!! *****" fi
The error we get is in line 5 [[, which seems the if command is not working.
I used the following example I found on the web for searching subtext in a text:
#example #STR='GNU/Linux is an operating system' #SUB='Linux' #if [[ "$STR" == *"$SUB"* ]]; then # echo "It's there." #fi