how to pass numeric array from bash to csh how to pass numeric array from bash to csh bash bash

how to pass numeric array from bash to csh


I'm not familiar with arrays in csh, but exporting seems easy enough:

in bash:

bdom=${BDOM[*]} mday=${MDAY[*]} ${PARTNER_FP}

You don't need the "env" command, bash has that built in.

To make $bdom into a list of words, instead of a single string, use ().in csh:

set bdom_array = ( $bdom )


bash doesn't let you export arrays. ("Yet", although it's been "not yet" for a long time.) So it's not that there is a problem exporting arrays from bash to csh. You can't export them from bash to bash either. (Nor, as far as I know, from csh to csh.)

There isn't really a great workaround either. You could use the printf '%q' format to print the elements out in a format which could be eval'd, but you'd have to do that every time you changed an array element, or at least every time you might need to import it into a subshell. Also, bash's printf doesn't necessarily export values in a format which csh's eval will understand.


As @rici points out, bash doesn't support exporting arrays - neither with export nor with env - and there's no robust workaround.

That said, if you know that:

  • the array elements contain no embedded spaces or other characters that need escaping
  • the array contains no elements that happen to be valid globbing patterns (e.g., '*')

then you can flatten your arrays into single-line, space-separated lists, and pass them that way.

In your example:

In array_writer.sh:

# export array as word list, i.e.:# as single-line string with space-separated tokensexport BDOM_LIST="${BDOM[@]}"

In array_reader.csh:

# Convert word list back into array.set BDOM=($BDOM_LIST)