I have a bash code (Mybash1.sh
) where the result I need to pass
to another bash code (Mybash2.sh
) that contain Python
Here are the codes. Mybash1.sh
#! /bin/bash
# Mybash1.sh
cut -f1,3 input_file.txt | sort | ./Mybash2.sh
Mybash2.sh is this:
#! /bin/bash
#Mybash2.sh
python mycode.py foo.txt <("$@") > output.txt
# do something for output.txt
The problem I have is that "output.txt" in Mybash2.sh
contain no result.
Is there a correct way to execute Python in Mybash2.sh
?
Note that mycode.py
will work if I run it on an intermediate temporary
file given from Mybash1.sh
. But I wanted to avoid using that, since I will call Mybash2.sh
in many instances within Mybash1.sh
.
Snippet of mycode.py
looks like this:
if __name__ == "__main__":
import sys, os, fileinput
progName = os.path.basename(sys.argv[0])
if len(sys.argv) != 3:
sys.exit('Usage: ' + progName + ' file1 file2')
file1 = fileinput.input(sys.argv[1])
file2 = fileinput.input(sys.argv[2])
# do something for file1 and file2
file1.close()
file2.close()