[英]How to execute commands from standard output?
I have a python script that print many commands if I execute python aaa.py
:我有一个 python 脚本,如果我执行
python aaa.py
,它会打印许多命令:
(base) tkl@TKL ~/Desktop python aaa.py
cp chart.xls ./me/chart.xls
find . | grep bro
scp -r fefe@192.168.1.4:/data/ti.exe .
Now I'm wondering if there's some linux command to execute these output as command sequencely and print all the output in the same shell, what I'm imaging is like that:现在我想知道是否有一些 linux 命令可以将这些输出作为命令顺序执行并在同一个 shell 中打印所有输出,我正在成像的是这样的:
python aaa.py | xargs -i execute {}
Does such 'execute' exist?这种“执行”存在吗?
bash
is the normal processor to execute a bunch of shell commands. bash
是执行一堆 shell 命令的普通处理器。 Like this:像这样:
{ echo date; echo ls; } | bash
So you could do this, if you trust your Python not to emit any "Bad Stuff" ™️所以你可以这样做,如果你相信你的 Python 不会发出任何“坏东西” ™️
python aaa.py | bash
Or, similarly, as suggested in the comments, you may specifically mean a POSIX shell, or sh
, in which case:或者,类似地,正如评论中所建议的,您可能特指 POSIX shell 或
sh
,在这种情况下:
python aaa.py | sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.