Linux command
expect 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Execute
expect [path/to/file]
Example
expect -c "[commands]"
Example
expect -i
说明
expect automates interactive applications by scripting responses to expected prompts. It spawns processes and responds to their output based on pattern matching. The tool uses Tcl scripting language with expect-specific commands like spawn, expect, and send. Scripts can handle multiple response patterns, timeouts, and conditional logic. This enables automation of programs that require interactive input like passwords, confirmations, or menu selections. Commonly used for automating SSH logins, FTP sessions, database setup scripts, and other interactive programs. While powerful, modern alternatives like SSH keys, API tokens, and configuration management tools are often preferred for security.
参数
- -c _commands_
- Execute the given Tcl/Expect commands before the script runs.
- -i
- Interactive mode (REPL). Also implied when stdin is a terminal.
- -f _FILE_
- Read the command script from FILE.
- -b _FILE_
- Read the script line-by-line (buffered mode) — useful for very long scripts.
- -d
- Enable diagnostic output (command tracing).
- -D _N_
- Enter the interactive debugger (on first prompt or after N expect calls).
- -v
- Print Expect version and exit.
- --
- End of options; following arguments are passed to the script in `$argv`.
FAQ
What is the expect command used for?
expect automates interactive applications by scripting responses to expected prompts. It spawns processes and responds to their output based on pattern matching. The tool uses Tcl scripting language with expect-specific commands like spawn, expect, and send. Scripts can handle multiple response patterns, timeouts, and conditional logic. This enables automation of programs that require interactive input like passwords, confirmations, or menu selections. Commonly used for automating SSH logins, FTP sessions, database setup scripts, and other interactive programs. While powerful, modern alternatives like SSH keys, API tokens, and configuration management tools are often preferred for security.
How do I run a basic expect example?
Run `expect [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c _commands_ do in expect?
Execute the given Tcl/Expect commands before the script runs.