명령의 표준 출력을 Expect 입력으로 어떻게 보내나요?

명령의 표준 출력을 Expect 입력으로 어떻게 보내나요?

LastPass CLI 유틸리티를 통해 비밀번호를 자동으로 채우는 쉘 + 기대 스크립트를 작성하고 싶습니다 lpass. lpass예상 스크립트의 비밀번호 입력으로 반환된 비밀번호를 보내는 방법을 잘 모르겠습니다 .

지금까지의 예상 스크립트는 다음과 같습니다.

# The beginning isn't important
expect -exact "\r
Please enter your username and password.\r
Username:"
send -- "my-username\r"
expect -exact "my-username\r
Password:"
send -- $(lpass show --password service\ im\ connecting\ to)
expect -exact "\r
# The rest of the expect script follows

$(...)의 비트가 실제로 어떻게 작성되어야 하는지 잘 모르겠습니다...

답변1

쉘에서 와 동일한 동작을 얻기 위해 스크립트 exec에서 함수를 사용하고 싶습니다.expect$(...)

아래 예를 참조하세요. 스크립트 없이 피드할 아래
외부 프로그램을 사용하겠습니다 .4expect.shexpect

#!/bin/sh
# Test program : let set filename as "4expect.sh"
# in the same directory where expect script will work

echo; read -p 'question: ' answer
echo "Got answer:>${answer}<"

그리고 여기에는 expect외부 프로그램의 "질문"을 기다리고 의 에서 사용할 현재 디렉터리의 전체 파일(외부 프로그램의 출력 가져오기 및 )을 제공하는 스크립트 lsegrep있습니다 .expectsend

#!/usr/bin/expect -f

spawn -noecho ./4expect.sh
expect -re "question" { send -- [exec ls -la . | egrep "^total" ]\r }
interact

puts "\nDone.\n"
exit

관련 정보