暂停shell脚本,直到preSS输入while循环 [英] Pause Shell script until Press Enter in while loop

查看:496
本文介绍了暂停shell脚本,直到preSS输入while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我读文件

示例脚本

while read file
do
temp = $(echo $file)
read -p "Press Enter to continue"
echo $temp
done < test.txt

我要暂停的脚本,直到我preSS ENTER

I want to pause the script until I press ENTER

推荐答案

从默认的标准输入,它被重定向到文件读取,因此它得到线从该文件。你可以回重定向到终端:

read reads from standard input by default, which is redirected to the file, so it's getting the line from the file. You can redirect back to the terminal:

read -p "Press Enter to continue" </dev/tty

另一种选择是使用不同的FD的文件重定向

Another option would be to use a different FD for the file redirection

while read -u 3
do
    ...
done 3< test.txt

这篇关于暂停shell脚本,直到preSS输入while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆