如何在该脚本中的数据库创建后传递sqlite查询..?

时间:2017-06-20 04:19:10

标签: mysql sqlite

*

一旦我在终端./demo_example.sh中执行此脚本,脚本将被执行,直到仅创建数据库。之后它将在sqlite>中构建。查询没有传递给sqlite。请问如何在脚本my output here中使用命令行传递sqlite查询

1 个答案:

答案 0 :(得分:0)

您必须通过在命令行中传递查询来使用非交互模式:

#!/bin/bash

echo " --- Enter the Database name ---"
read databasename


echo " --- Enter the Table details --- "

sqlite3 $databasename.db  "CREATE TABLE IF NOT EXISTS CUSTOMER_DETAILS(cus_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,cus_name TEXT NOT NULL,cus_domain TEXT UNIQUE, cus_status TEXT NOT NULL,Port INTEGER NOT NULL);"


#echo " --- Enter the total number of customer records ---"
read cus_count

for((i=0;i<=cus_count;i++))
do
read c_name
read c_domain
read c_status
read port

sqlite3 $databasename.db "INSERT INTO CUSTOMER_DETAILS(cus_name,cus_domain,cus_status, Port) VALUES(\"$c_name\",\"$c_domain\",\"$c_status\",\"$port\");"

done

#echo " --- select the records from the table ---"

sqlite3 $databasename.db "select * from CUSTOMER_DETAILS;"