これは非常に単純化された例です。
# expect -c "spawn socat -v -,raw,echo=0,nonblock /dev/ttyS0; interact"
expect
生成されるインラインスクリプトを実行します socat
に接続するために serial
端末。しかし、もし私たちが bash
シリアルと呼ばれる関数(非常に便利です):
# serial(){ socat -v -,raw,echo=0,nonblock /dev/ttyS0;}
# expect -c "spawn serial; interact"
spawn serial
couldn"t execute "serial": no such file or directory
while executing
"spawn serial"
強制することは可能ですか? expect
ラッパースクリプトまたはバイナリなしで関数を実行するには?
回答:
回答№1は1内部でbash関数または組み込みを実行するには spawn
、関数またはビルトインを実行するbashサブプロセスのスポーンにする必要があります。これは -c
bashのオプション。bashを実行するための小さなインラインスクリプトを指定できます。
spawn bash -c "serial"
あなたは シングル 後の議論 -c
実行するインラインスクリプトです。その後の引数はbashの定位置パラメーターに割り当てられます。
回答№2については2
あなたはできる export
シェル関数なので、新しい spawn
edシェルはそれを呼び出すことができます。例えば:
% cat foo.sh
the_func()
{
echo hello world
}
export -f the_func
expect -c "spawn bash -c the_func; interact"
% bash foo.sh
spawn bash -c the_func
hello world
%