kaviranga kaviranga - 5 months ago 19
Bash Question

How to check tinyint column value in mysql table is true or false using linux bash scripting?

I have mysql database table that have the following structure

+------+-------------+----+----+--------+----------------+
| Field| Type |Null|Key | Default|Extra |
+------+-------------+----+----+--------+----------------+
|id |int(11) |NO |PRI | NULL | auto_increment |
|c_date|date |NO | | NULL | |
|c_time|time |NO | | NULL | |
|number|varchar(11) |NO | | NULL | |
|data |varchar(150) |NO | | NULL | |
|isSent|tinyint(1) |NO | | NULL | |
+------+-------------+----+----+--------+----------------+


What I want is to check whether isSent field's value is true or false or ,0 or 1 using a linux bash script.

Answer

using below query you can get the result into variable

count=$(echo "SELECT isSent FROM TABLE WHERE ...." | mysql <DB> -u -p -h localhost)

echo $count
Comments