I have an array HSPACE which is defined inside a python script. I am trying to pass this array to a shell script "arraytest" and execute it from python itself. I am trying with the following piece of code but it doesnt seem to be working:
HSPACE=[0.01, 0.009, 0.008, 0.007]
subprocess.call(["./arraytest"], HSPACE, shell=True)
The content of the shell script is:
#!/bin/bash
for i in ${HSPACE[@]}
do
echo $i
done
shell=Trueunless you have a compelling reason and know exactly why you're using it; it adds substantial complexity and security exposure.${HSPACE[@]}-- while not useful here because HSPACE isn't inherited (arrays can't be exported through the environment, so it's not just a matter of syntax but feasibility) -- is incorrect syntax to expand an array's contents while keeping the original division between element boundaries; it behaves precisely identically to${HSPACE[*]}, which combines elements of the array with the first character ofIFSand then subjects the result to string-splitting and globbing. To avoid this, you need to quote:"${HSPACE[@]}".evals to array contents, but the shell receiving and evaluating it needs to trust the source of that value, making it a poor practice and prone to creating shell injection vulnerabilities if not done properly).H:0.01 H:0.009 H:0.008 H:0.007 V:1.23 V:4.56is an example of what the latter argv would look like; the shell script could then just iterate over"$@"and assign each item to the correct array based on its prefix.