系统相关
首页 > 系统相关> > linux – 在后台运行heredoc格式化脚本?

linux – 在后台运行heredoc格式化脚本?

作者:互联网

我想知道是否有任何方法可以在后台以heredoc格式运行脚本?

#!/bin/bash

python <<EOF
import time
time.sleep(2)
print "AAA"
EOF  # placing "&" here doesn't work

echo "Hello"

我知道我可以将它写入文件,然后像python foo.py&但这不是问题的关键.

解决方法:

坚持你的&在顶部,这完全不直观,但……也不是heredocs.

#!/bin/bash

python <<EOF &
import time
time.sleep(2)
print "AAA"
EOF 

echo "Hello"

你也可以在那里重定向:

#!/bin/bash

python <<EOF > /some/file &
import time
time.sleep(2)
print "AAA"
EOF 

echo "Hello"

标签:heredoc,bash,linux
来源: https://codeday.me/bug/20190829/1758358.html