Pass multiple arguments from single line from a text file to teminal
0
votes
2
answers
297
views
I have a python program that requires 2 arguments input-file and output-file.
It reads input-file and creates a copy of that file with some modifications in the output-file.
I created a text file with a set of arguments. It has multiple sets of arguments on multiple lines. But for 1 execution of a program it needs to read line by line. So each line has 2 args (separated by a space) to be passed: input-file and output-file.
Example of file with arguments (call it *File-With-Multiple-Arguments-Per-Line.txt*):
input-file-1-path/input-file-1-name.sql output-file-1-path/output-file-1-name.sql
input-file-2-path/input-file-2-name.sql output-file-2-path/output-file-2-name.sql
input-file-3-path/input-file-3-name.sql output-file-3-path/output-file-3-name.sql
input-file-4-path/input-file-4-name.sql output-file-4-path/output-file-4-name.sql
I tried this:
for arg in $(`
But using
"$arg" "$arg"
leads to incorrect interpretation of my program. As if does the same task 3 times - first time does what is intended; second time using input-file as output and input; third time using output-file as output and input.
I've tried the solution below as well, but then my program does not do anything. Though it displays the output in my terminal as if it did what was supposed to be done. And no error appears.
For reference: https://unix.stackexchange.com/questions/429834/reading-multiple-arguments-for-a-shell-script-from-file
while read x y; do
python /Users/Git-Repos/MyProgram.py "$x" "$y"
done < /Users/Repository/File-With-Multiple-Arguments-Per-Line.txt
Asked by Data Engineer
(113 rep)
Nov 3, 2023, 12:15 AM
Last activity: Nov 3, 2023, 04:55 PM
Last activity: Nov 3, 2023, 04:55 PM