Arrays are not a solution to this problem, especially non-associative arrays. Even if they exit in the same order, you will have multiple keys for single -k, which leads to a syntax error. Also arrays are a Bashism , and are not defined by POSIX. A better solution would be something like this:
./foo.py -k key1,key2,key3 -v val1,val2,val3
Then of course Python can break the input lines? I did something similar with the POSIX shell:
tr , '\n' > keys <<eof $1 eof tr , '\n' > vals <<eof $2 eof paste -d '\n' keys values | while read key read val do printf 'key: %s, val: %s\n' "$key" "$val" done
Of course, that would be a lot easier with Python, since you could just split strings directly into arrays without using files.
source share