运行 在后台使用 heredoc 格式的脚本?
Run heredoc formated script on background?
我想知道有什么办法可以运行后台的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格式的脚本吗?
#!/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"