如何将多个命令在Shell脚本中的一个变量中组合输出?

发布于 2025-01-26 12:25:30 字数 232 浏览 1 评论 0原文

我正在使用以下脚本获取数据库文件中的一个变量的数据

#!/bin/bash

sqlite3 pdu.db <<'END_SQL'
.timeout 2000
SELECT Variable_Value FROM Data Where Sr_No'7';
END_SQL

,现在我想将上述命令的输出存储在一个变量中。我们如何将多个命令输出存储在shell脚本中的一个变量中?

I'm using the following script to get the data of one of the variables from the database file

#!/bin/bash

sqlite3 pdu.db <<'END_SQL'
.timeout 2000
SELECT Variable_Value FROM Data Where Sr_No'7';
END_SQL

Now I wanted to store the output of the above commands in one variable. How we can store multiple commands output in one variable in the shell script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌若浮生 2025-02-02 12:25:30

不限制将多行命令放入命令替代。

variable=$(sqlite3 /var/www/dbs/ha.db <<'END_SQL'
.timeout 2000
INSERT INTO table1 SELECT * FROM table2;
DELETE FROM table2;
END_SQL
)

There's no restriction against putting a multiline command inside a command substitution.

variable=$(sqlite3 /var/www/dbs/ha.db <<'END_SQL'
.timeout 2000
INSERT INTO table1 SELECT * FROM table2;
DELETE FROM table2;
END_SQL
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文