小编Igo*_*nko的帖子

如何从管道读取用户输入?

假设我有一个以confirmation.sh以下内容命名的文件:

#!/bin/bash
echo -n "Are you sure [Y/n]? "
read line
case "$line" in
    n|N) echo "smth"
        ;;
    y|Y) echo "smth"
        ;;
esac
Run Code Online (Sandbox Code Playgroud)

我想通过以下方式运行这个脚本:

cat confirmation.sh | sh
Run Code Online (Sandbox Code Playgroud)

我看到Are you sure [Y/n]?了,剧本被打断了。有什么问题?

shell pipe shell-script user-input

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

pipe ×1

shell ×1

shell-script ×1

user-input ×1