bash - 如何在bash脚本中运行sqlite3?

标签 bash sqlite heredoc

我想在bash脚本中运行一系列sqlite命令:

db="main.sqlite3"
db2="sub.sqlite3"

sqlite3 ${db} <<EOF
attach ${db2} as m;
select count(*) from m.details;
.exit
EOF


当附加到字符串时,它可以工作,但是当它是一个变量时,它就不会

Error: near line 1: near "/": syntax error


如何在EOF中使用变量(db2)?谢谢

最佳答案

尝试将数据库文件附加到双引号中:

attach "${db2}" as m;

关于bash - 如何在bash脚本中运行sqlite3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45689062/

相关文章:

python - 使用 heredoc 创建一个新的文本文件

sqlite - 使用 SyncAdapter 在 Android 上进行双向同步

bash -/dev/stdin 与 herestring

linux - 如何对 csv 文件执行逐行操作?

bash - 如何将 .po 文件编译为 .mo 文件,msgfmt 不起作用

postgresql - 如何将 postgres 数据库转换为 sqlite

iphone - 我可以用sqlite运行带有20万条记录的iPad吗?

PHP 文档语法

bash - 如何在 bash 中转义 sqlite3 查询参数?

bash - 检索子 shell stdout 的第一行/最后一行