当用户想要关闭它时从 bash 脚本退出 STDIN

exit from STDIN from bash script when the user want to close it

我正在通过 bash 脚本自动创建文件。我生成了一个文件 rc_notes.txt,其中包含来自两个标签的提交消息,并希望在新文件中将其重写为 rc_device.txt.

我希望用户写下客户发布说明并退出我在终端提示的BASH STDIN

我的脚本中的问题是我无法捕获文件的关闭。

想知道怎么做。我不想捕获关闭信号。我想输入魔术字符串示例:Done 或一些触发 STDIN 关闭的字符串,从脚本中正常退出。


我的脚本:

#/bin/bash

set -e


echo "Creating the release candiate text"
rc_file=rc_updater_notes.txt
echo "=========Reading the released commit message file=========="
cat $rc_file
echo "=========End of the commit message file=========="

echo "Now write the release notes"

#exec  < /dev/tty
while read line
do
  echo "$line"
done < "${1:-/dev/stdin}" > rc_file.txt

它确实创建了文件,但我需要通过输入 ctrl+Dctrl+z 手动退出。我不想那样做。有什么建议吗?

输入"Done"时打破循环

while read line
do
    if [[ $line = Done ]]; then
        break;
    fi
    echo "$line"
done < "${1:-/dev/stdin}" > rc_file.txt

while read line && [[ $line != Done ]]
do
    echo "$line"
done < "${1:-/dev/stdin}" > rc_file.txt