I have created a script in bash. I need to check if take 0 number then ignore this, but if take some value then I need to calculate based on the value given and print the result.
Here is an example:
if [ "$max_users_conn" -ne "0" ]; then
let "percentage="$process_list"*100/"$max_users_conn""
echo "$percentage"
fi
However, when I run the code, I receive the following error:
./mysql_conn.sh: line 14: [: 0 10: integer expression expected ./mysql_conn.sh: line 14: [: 0 10: integer expression expected ./mysql_conn.sh: line 14: [: 5 5: integer expression expected 0 20
I also tried to run it like this:
if [ "$max_users_conn" != "0" ]; then
let "percentage="$process_list"*100/"$max_users_conn""
echo "$percentage"
fi
But this gives a different error:
./mysql_conn.sh: line 15: let: percentage=4*100/0: division by 0 (error token is "0") ./mysql_conn.sh: line 15: let: percentage=4*100/0: division by 0 (error token is "0") 0 0 20