Skip to content

Instantly share code, notes, and snippets.

@x-yuri

x-yuri/2.sh Secret

Last active September 4, 2017 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-yuri/c746d51cb075269731122ee739f06c46 to your computer and use it in GitHub Desktop.
Save x-yuri/c746d51cb075269731122ee739f06c46 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eu
echo '
spawn ./1.sh
expect >
send cmd1\n
expect "\nd " ;# it matches
send quit\n
' | expect -d
$ ./2.sh
expect version 5.45 [6/91679]
argv[0] = expect argv[1] = -d
set argc 0
set argv0 "expect"
set argv ""
executing commands from command file
spawn ./1.sh
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {31239}
expect: does "" (spawn_id exp6) match glob pattern ">"? no
>
expect: does "> " (spawn_id exp6) match glob pattern ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) ">"
send: sending "cmd1\n" to { exp6 }
expect: does " " (spawn_id exp6) match glob pattern "d"? no
cmd1
expect: does " cmd1\r\n" (spawn_id exp6) match glob pattern "d"? yes
expect: set expect_out(0,string) "d"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " cmd"
send: sending "quit\n" to { exp6 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment