forループ内の自動提案で「一重引用符」テキストのみを自動的にコピーして貼り付ける方法は?

forループ内の自動提案で「一重引用符」テキストのみを自動的にコピーして貼り付ける方法は?

forループを使用して有効期限が切れた複数のディレクトリを検索するコマンドを作成しています。システムには、私が人間であることを確認するセキュリティチェック機能があります。

$ for x in $(exp-dir); do 
clean_command $x
done

システムは自動的にインタラクティブシェルを実行するように求められます。完了するには、引用符付きテキスト(forループの各$ xに対して)をコピーして貼り付ける必要があります。

$ to verify that you are human, please type 'xyzylans':
you are human
Info: restore successful.

一重引用符で囲まれたテキストを解析、コピー、渡す方法、つまりループを完全に自動化する方法はありますか?

ベストアンサー1

$ cat testscript.sh
#! /bin/bash

string='xyzylans'
echo "to verify that you are human, please type '${string}':"
read cmpstring
test "$string" = "$cmpstring"
echo $?

stdinとを使用すると、stdout次のことができます。

coproc ./testscript.sh
awk -F\' "/^to verify that you are human, please type '.*':\$/ "\
"{ print \$2; exit };" <&${COPROC[0]} >&${COPROC[1]}
cat <&${COPROC[0]}

おすすめ記事