我有一个名为 f 的 Bash 脚本,其中包含 Python 代码。该 Python 代码从标准输入读取内容。我希望能够按以下方式调用我的 Bash 脚本:
f input.txt > output.txt
在上面的示例中,Python代码将从input.txt读取并写入output.txt。
我不确定如何做到这一点。我知道如果我只想向文件写入,那么我的bash脚本会像这样。#!/bin/bash
python << EOPYTHON > output.txt
#python code goes here
EOPYTHON
我尝试将上述代码中的第二行更改为以下内容,但没有成功
python << EOPYTHON $*
我不确定还有什么其他方式来做这件事。有任何建议吗?
编辑 我将给出一个更具体的示例。考虑以下bash脚本,f
#!/bin/bash
python << EOPYTHON
import sys
import fileinput
for i in fileinput.input():
sys.stdout.write(i + '\n')
EOPYTHON
我想用以下命令运行我的代码
f input.txt > output.txt
我该如何修改我的 Bash 脚本,以便将 "input.txt" 作为输入流使用?