我要用 bash 编写脚本,我想从另一个应用程序读取输出,并要求用户采取行动。
psql -c "SELECT userid, name FROM my_table"|
while read userid name
do
do_something $userid $name
done
在函数 do_something 内部我想问“你确定吗等”。但这对我不起作用。
最佳答案
read output from another application
ls -1 |读我时;做 echo "$i";完成
ls -1
,类似输出
|
重定向输出
read
,获取输出并放入 i
"$i"
,现在可以打印了
现在,在你的 while
中你可以做任何事情,比如调用一个函数或其他东西
阅读:
阅读 --help
作为脚本:
for i in $(ls -1)
do
echo -n "Are you sure (y/n)?" && read ans
if [ $ans == "y" ];then
echo $i
fi
done
关于linux - 在 bash 循环中读取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38460840/