I have 2 variables in bash. Using test i found out that one of them is integer and other one is string. I want to compare them and see if they are equal. I tried the following options.
if [ "$a" -eq "$b" ] if [[ "$a" -eq "$b" ]] if [ "$a" = "$b" ] if [[ "$a" = "$b" ]]
I tried converting the string variable to integer as
a=$(($a+0))
but I got the following error
+0")syntax error: invalid arithmetic operator (error token is "
None of them are providing me the expected result. Please tell me what I am doing wrong?
I have multiple CSV files. The second field of the last row in each of these files will contain the number of rows in that file. I have to get the row count from the file and compare it against the actual number of rows in the file. If they are same, then only I have to process.
ROW_COUNT=`grep -c ^ /tmp/file1.csv` --This is the number LAST_LINE=`tail -n 1 /tmp/file1.csv` ACTUAL_ROW_COUNT=`echo ${LAST_LINE} | cut -d "," -f 2` --This is the string --now i am comparing these two numbers to see if they are same. if [[ ${ROW_COUNT} == "${ACTUAL_ROW_COUNT}" ]]; then -- Here it is breaking
-eq
will compare them as integers,=
will compare them as strings. You don't need to convert the string first.$a
, and what is the exact statement you used?