循环,数组,mysql,bash,linux
我想编写一个将选择发送到响应中数据库的脚本,
data_path="https://localhost/public/"
data_name=(PXL_20220628_152928222.mp4 PXL_20220628_163301667.mp4)
for q in "${data_name[@]}";
do
data_l=$(sudo mysql -h localhost -P 3306 -u ck****** -p"*******" -e "SELECT iddata FROM
ck*****.data WHERE links = '$data_path$q'")
done
echo "$data_l"
我只会得到一个记录(ID第一个文件PXL_20220628_1529282222.MP4)
循环不起作用
I want to write a script that sends the select to the database
data_path="https://localhost/public/"
data_name=(PXL_20220628_152928222.mp4 PXL_20220628_163301667.mp4)
for q in "${data_name[@]}";
do
data_l=$(sudo mysql -h localhost -P 3306 -u ck****** -p"*******" -e "SELECT iddata FROM
ck*****.data WHERE links = '$data_path$q'")
done
echo "$data_l"
In response I get only one record (id first file PXL_20220628_152928222.mp4 )
The loop is not working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将您的脚本复制到使用Shebang的文件中,在
sudo
的前面添加了echo
,以显示被执行的命令,并在内部循环后移动一个显示结果。运行它:
您是在分配它,但没有报告它,然后用第二个任务覆盖它,并且仅报告循环完成后的一个。
只需在循环内的末端移动回声即可。
I copied your script to a file with a shebang, added an
echo
in front of thesudo
to show the command being executed and moved the one AFTER the loop inside to show the result.Running it:
You were assigning it, but not reporting it, then overwriting with the second assignment, and only reporting that one after the loop was done.
Just move the echo at the end inside the loop.