在下一行的提示后面打印bash脚本结果 [英] Print bash script result behind prompt in the next line

查看:82
本文介绍了在下一行的提示后面打印bash脚本结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回命令的Bash脚本.我想执行该脚本,并使其在下一行的提示后面自动打印结果.也可以选择替换当前行中的脚本调用.这样,我可以在执行命令之前对其进行编辑. 可以在带有Bash的终端中实现吗?

I have a Bash script that returns a command. I would like to execute the script and let it automatically print the result behind the prompt in the next line. Replacing the script call in the current line would be an option too. This way I could edit the command before I execute it. Can this be achieved within a terminal with Bash?

推荐答案

如果在 tmux 中运行bash(终端多路复用器),则可以使用其缓冲功能在命令提示符下粘贴命令.然后,您可以在运行命令之前对其进行编辑.这是一个简单的示例:

If you run bash within tmux (terminal multiplexer), you can use its buffer functions to paste a command at your prompt. You can then edit the command before running it. Here's a trivial example:

#!/bin/bash
tmux set-buffer 'ls -l'
tmux paste-buffer &

在后台放置paste-buffer命令,让我们在粘贴发生之前bash输出提示.如果粘贴发生得太快,你可以加一分一秒的睡眠像这样:

Putting the paste-buffer command in the background let's bash output the prompt before the paste happens. If the paste happens too quickly, you can add a sub-second sleep like so:

#!/bin/bash
tmux set-buffer 'ls -l'
{ sleep .25; tmux paste-buffer; } &

这篇关于在下一行的提示后面打印bash脚本结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆