ユーザーの対話を待っているバックグラウンドスクリプトにキーボードイベントを送信できますか? (「読む」を使用してください)

ユーザーの対話を待っているバックグラウンドスクリプトにキーボードイベントを送信できますか? (「読む」を使用してください)

前任者:

$read &
[1] 15139

[1]+  Stopped    
$jobs -l
[1]+ 15139 Stopped (tty input) read

ベストアンサー1

これはfifoを使って簡単に行うことができます。

$ cat bar.sh
#!/bin/sh
read bar
echo got $bar in the read line

$ mkfifo foo
$ ./bar.sh < foo &
$ echo hello > foo 
$ got hello in the read line
[1]+  Done                    ./bar.sh < foo
$ 

おすすめ記事