简体   繁体   English

如何同时执行两个Shell函数?

[英]How can I execute two shell functions at the same time?

I have written a shell script with functions which output some ASCII animation. 我已经编写了一个shell脚本,其功能可以输出一些ASCII动画。 I would like to execute two of these functions at the same time but have them display the art one under the other, for example: 我想同时执行其中两个功能,但让它们在另一个功能下展示艺术品,例如:

function_one(){
clear
printf %s '
______________
||__________||

'
sleep 1
tput home
printf %s '
______________
||__________||
      ||
      ||
      ||

'
sleep 1
tput home
printf %s '
______________
||__________||
      ||
      ||
      ||
||‾‾‾‾‾‾‾‾‾‾||
‾‾‾‾‾‾‾‾‾‾‾‾‾‾
'
}

imagine this function continues to print more ASCII letters but in the same set of 7 lines it has already taken then underneath this I want another function to start: 想象这个函数继续打印更多的ASCII字母,但是在同一行的7行中它已经被占用了,然后在这个下面我要启动另一个函数:

function_two(){
sleep 10
printf %b "this is an example\r"
printf %b "this is more example\r"
printf %b "and some more\r"
}

function_two sleeps for a while to allow function_one to take all the space it needs but starts before function_one has finished and displays its output below function_one. function_two会睡一会儿,以允许function_one占用所有需要的空间,但会在function_one完成之前启动并在function_one下面显示其输出。 Is this possible? 这可能吗? I have tried piping the functions, eg: 我试过管道功能,例如:

function_one | function_two

but this only seems to execute function_two. 但这似乎只执行function_two。 Sorry, this isn't the easiest thing to explain but I hope you can understand. 抱歉,这不是最简单的解释,但希望您能理解。 Thank you. 谢谢。

Advanced control of where on a display to print isn't something you can do trivially. 您无法轻易地实现对显示器上打印位置的高级控制。 You need to specify where to draw/etc. 您需要指定绘图位置/等。

Pipes send the output from one command to another command (so function_two there gets on its standard input the output from function_one which isn't at all what you want). 管道将输出从一个命令发送到另一个命令(因此function_two在其标准输入上获得了function_one的输出,而这根本不是您想要的)。

If you just don't want function_two to wait for function_one to finish put function_one in the background with & . 如果您只是不想让function_two等待function_one完成,请在&后面放上function_one

function_one &
function_two

But if function_one isn't done printing this isn't going to work how you want it to. 但是,如果未完成function_one打印,将无法按照您的要求进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C中独立执行两个函数 - Execute two functions at the same time independently in C 当它们位于不同目录中时,如何同时运行两个程序? (Tcsh外壳) - How can I run two programs at the same time, but when they are in different directories? (Tcsh shell) 如何通过将每个命令分配给线程来在C ++中同时执行linux系统命令? - How can I execute linux system commands at same time in C++ by assigning each command to threads? 如何传递多个参数并使用 echo 执行 shell 脚本 - How can I pass multiple arguments and execute shell script with echo Shell编程:同时执行两个应用程序 - Shell programming: Executing two applications at the same time 如何在Bash子shell中执行shell脚本? - How can I execute a shell-script in a Bash sub-shell? 在同一shell中执行一个块 - Execute a block in the same shell 如何在外壳程序脚本中包含html? 执行shell脚本时能否获得html格式的输出? - How can I include html in my shell script? Can I get html formatted output when I execute my shell script? 如何使用Shell脚本计算文件中两个时间条目之间的时间跨度? - How can you can calculate the time span between two time entries in a file using a shell script? 当两个进程试图同时执行perl文件时,会发生“文本文件繁忙”吗? - Can “Text file busy” happen when two processes trying to execute a perl file in the same time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM