Using read -p in a bash script that was executed from pipe

后端 未结 2 1104
予麋鹿
予麋鹿 2021-01-13 02:37

I apologize in advance - I don\'t fully understand the ideas behind what I\'m asking well enough to understand why it\'s not working (I don\'t know what I need to le

2条回答
  •  臣服心动
    2021-01-13 03:37

    The tty solution works. Test it with this code, for example:

    $ date | { read -p "Echo date? " r 

    The prompt from read appears on the terminal and read waits for a response before deciding to echo the date or not.

    What I wrote above differs from the line below in two key aspects:

    read -t 1 __response 

    First, the option -t 1 gives read a timeout of one second. Secondly, this command does not provide a prompt. The combination of these two probably means that, even though read was briefly asking for input, you didn't know it.

提交回复
热议问题