将信息发送到 shell 中的提示符
我使用 CLI 在 shell 中启动提示符。但是,我通常最终会在提示符下键入相同的命令。有没有一种方法可以手动自动启动 CLI,然后一次性发送输入?
下面是一个示例:我输入 spotify
来启动我的音乐客户端。 我看到:(
Type help to see commands.
> list
These are your playlists
1. ...
2. ...
省略了一些行)其中“>”是我正在输入的提示。我希望我的脚本为我输入 list
,然后 play
,然后 quit
,然后启动一个播放我的 iTunes 库的脚本。我该怎么做呢?
I use a CLI that starts a prompt in my shell. However, I usually end up typing the same commands at the prompt. Is there a way to manually automate the starting of the CLI and then send input in one go?
Here is an example: I type spotify
to start my music client.
I see:
Type help to see commands.
> list
These are your playlists
1. ...
2. ...
(some lines omitted) where ">" is a prompt I am typing at. I want my script to type list
for me then play
and then quit
and then start a script which plays my iTunes library. How could I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Expect 是我正在寻找的。它是一个专门用于此目的的 UNIX 测试和自动化工具。
Expect is what I was looking for. It's a UNIX testing and automation tool for exactly this purpose.
您可以实现“宏录制”。例如,如果您键入“startrec”,CLI 可以保存所有后续命令,例如“list”、“play”和“quit”。您输入“stoprec spotify”,它将命令列表存储在标题“spotify”下。下次当您键入“spotify”时,您的 CLI 可以在宏列表中找到它,并重播命令序列。
You could implement "macro recording". For example, if you type "startrec", the CLI could save all subsequent commands, e.g. "list", "play" and "quit". The you type "stoprec spotify", which stores the command list under the title "spotify". next time when you type "spotify" your CLI could find it in the macro list, and replay the command sequence.