When you export variable from the shell, what you really do is add it to the POSIX "environment" array, which inherits all the child processes. But the POSIX environment is a flat array of strings name = value; it itself cannot contain arrays. Therefore, Bash does not even try to put arrays. It will give you export array variable, and even set the "exported" flag for this variable, but the environment is not affected. You can verify this fact by running env or a new copy of bash and selecting the βexportedβ variable:
$ export myArr=(this is an array) $ bash -c 'echo "${myArr[@]}"' $
(Some other shells with an array, in particular ksh, actually export the array variable to the environment, but the exported value will consist only of the first element of the array.)
If you want to pass a shell array to a Python script, it is best to do this as command line arguments. If you run the Python script as follows:
python code.py "${mdcNo[@]}"
... then Python code can just go through sys.argv , which is always a list. (In particular, the passed array will be a slice of sys.argv[1:] , since sys.argv[0] always specified by the name of the script itself.)
If this is not an option, you will have to set the environment variable to a string with some separator between the elements and split it inside the Python code. Something like that..
Bash:
export mdcList='0021,0022,0036,0055,0057,0059,0061,0062,0063,0065,0066,0086,0095,0098,0106,0110,0113,0114,0115,0121,0126,0128,0135,0141,0143,0153,0155,0158'
Or you can build a string from an array:
export mdcList=${mdcNo[0]} for i in "${mdcNo[@]:1}"; do mdcList+=,$i done
In any case, the Python script can restore the array as a list:
mdc_no = os.getenv('mdcList').split(',')
If your array elements are not just numbers, you can replace the comma with something less likely to be displayed in the element; the traditional choice would be the ASCII Unit Separator (U + 001F, $'\x1f' in Bash, '\x1f' in Python).