[英]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.