Hi All,
Trying to get my bash script if statement to work however my if variable equals xxx statement doesnt appear to work, could anyone shed some light.
./script $password &> output
INCORRECTPASS=`grep "Permission denied, please try again." output`
echo "$INCORRECTPASS"
if [[ $INCORRECTPASS == "Permission denied, please try again." ]]; then
echo "Incorrect Password"
fi
As you can see i have put in an echo to print the variable set and this prints sucessfully so I know for sure the variable exists.
Would have been wise to post the error msg as well, so we don't have to guess... My guess is, if sees too many words in the first operand. Try quoting the variable.
#!/bin/bash
clear
+ clear
echo -e "\033[1;94m";
+ echo -e '\033[1;94m'
echo "Checking input file"
+ echo 'Checking input file'
Checking input file
if grep -nv '^44[0-9]\{10\}$' numberlist.txt
then
echo -e "\033[1;31m";
echo 'Please check the above entries in the numberlist.txt file.'
echo -e "\033[1;37m";
exit
fi
+ grep -nv '^44[0-9]\{10\}$' numberlist.txt
sleep 1
+ sleep 1
echo "***************************************************************************************************************"
+ echo '***************************************************************************************************************'
***************************************************************************************************************
echo "The Script is currently in progress, exiting from this window will stop the script and cause it not to complete"
+ echo 'The Script is currently in progress, exiting from this window will stop the script and cause it not to complete'
The Script is currently in progress, exiting from this window will stop the script and cause it not to complete
echo "***************************************************************************************************************"
+ echo '***************************************************************************************************************'
***************************************************************************************************************
VAR=`grep -c "44" numberlist.txt`
grep -c "44" numberlist.txt
++ grep -c 44 numberlist.txt
+ VAR=1
echo "The amount that will be checked is $VAR"
+ echo 'The amount that will be checked is 1'
The amount that will be checked is 1
./msscript $1 &> expectoutput
+ ./msscript random
INCORRECTPASS=`grep "Permission denied, please try again." expectoutput`
grep "Permission denied, please try again." expectoutput
++ grep 'Permission denied, please try again.' expectoutput
' INCORRECTPASS='Permission denied, please try again.
echo "$INCORRECTPASS"
' echo 'Permission denied, please try again.
Permission denied, please try again.
if [[ "$INCORRECTPASS" == "Permission denied, please try again." ]]; then
echo "Incorrect Password"
fi
== \P\e\r\m\i\s\s\i\o\n\ \d\e\n\i\e\d\,\ \p\l\e\a\s\e\ \t\r\y\ \a\g\a\i\n\. ]]
cat expectoutput | tr -d $'\r' | awk '{print}' ORS=', ' | grep -o 'MS ??[^\n]*' | sed 's/\--//g' | sed 's/\Please e//g' | sed 's/\--//g' | sed 's/;.*//' | sed 's/\MS ??,//g' | sed 's/\ //g' > intialout
+ cat expectoutput
+ tr -d $'\r'
+ awk '{print}' 'ORS=, '
+ grep -o 'MS ??[^\n]*'
+ sed 's/\--//g'
+ sed 's/\Please e//g'
+ sed 's/\--//g'
+ sed 's/;.*//'
+ sed 's/\MS ??,//g'
+ sed 's/\ //g'
echo "CREATING CSV FILE CALLED relay-finaloutputfile.csv"
+ echo 'CREATING CSV FILE CALLED relay-finaloutputfile.csv'
CREATING CSV FILE CALLED relay-finaloutputfile.csv
#rm expectoutput
#rm intialout