Question

The following works in tcsh:

set SOMEVAR=(1 2 3 4 5 6 7)

I need to propagate SOMEVAR to a subprocess, but

truffles:rlaplant[154] setenv SOMEVAR (1 2 3 4 5 6 7)
Badly placed ()'s.

(I have to do this in csh because I have to source the output of some very complex scripts, and it would be a lot of effort to translate them all to Bash.)

Is there a way to do this?

Was it helpful?

Solution

csh's internal shell variables can be either strings or arrays. Environment variables can only be strings.

For example, the csh shell variable $path mirrors the environment variable $PATH. $path is an array of directory names; $PATH is a single string, consisting of the same directory names separated by : characters.

You're going to have to shove your array values in single strings, using some consistent syntax to indicate that they're meant to be arrays. If the elements can never contain any whitespace, then separating the words by spaces is good enough. Otherwise, you might consider using the same mechanism used by $PATH and separate the elements by : characters.

If the elements can contain : characters, and you can't pick some other character that will never appear, things get more complicated. You'll just have to do a bit of programming.

Obligatory link

OTHER TIPS

You could use this workaround:

set tempvar=(1 2 3 4 5 6 7)
setenv somevar "$tempvar"

Although I'm not sure it will remain an array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top