I'm trying to compare two strings in this if statement but I want to remove all characters that aren't alphanumeric and I'm having a hard time doing so. Right now, the following will empty the $adbsn variable. What I'm doing wrong exactly?
adbsn=`adb get-serialno` | tr -d '\r' | tr -d '\n'
echo ""
echo "Actual ADB device serial number: $adbsn"
echo ""
if [[ "$adbsn" == "SDCARD2" ]]; then
echo "*************************************************************"
echo "uSD card properly booted. Program will continue in 4 seconds."
echo "*************************************************************"
sleep 4
#elif [[ "$adbsn" = -z ]]; then
# echo "***********************************************************************************"
# echo "Sorry. No ADB device/uSD have been detected."
# echo ""
# echo "1. Did you properly plugged the USB cable ?"
# echo "2. Does the canvas is powered on ?"
# echo ""
# echo "Program will end."
# echo "***********************************************************************************"
else
echo "**********************************************"
echo "You didn't boot from the uSD..."
echo ""
echo "1. Did you insert the uSD card ?"
echo "2. Do you need a jumper to boot from the uSD ?"
echo ""
echo "Program will end."
echo "**********************************************"
exit 0
fi
So yeah, I have two options in my point of view, I can remove the undesired characters when I declare my variable (which makes more sense to me) or change the SDCARD2 string in my if statement to add the undesired character. Let me know what you guys think. This is my first bash if statement by the way.
AzureAD+Jean-PhilippeBegin@JPB-LENOVO /cygdrive/c/bash_scripts
$ adb get-serialno > /tmp/junk
AzureAD+Jean-PhilippeBegin@JPB-LENOVO /cygdrive/c/bash_scripts
$ od /tmp/junk
0000000 042123 040503 042122 006462 000012
0000011
AzureAD+Jean-PhilippeBegin@JPB-LENOVO /cygdrive/c/bash_scripts
$ od -c /tmp/junk
0000000 S D C A R D 2 \r \n
0000011
Aucun commentaire:
Enregistrer un commentaire