Read variables from a text file for use in csh script

Hello,

I have a text file (say, declarevars.txt) that contains multiple lines that are essentially meant to be variable declarations:

set arr1 = (var1a var1b var1c)
set arr2 = (var2a var2b var2c)
.
.
.

I want to be able to read this text file within a csh (sorry) script and have that script treat these lines as if they are part of the script. That is, after reading the text file, if I write

echo $arr1

within the script, it would print out

var1a var1b var1c

My reason for doing this instead of setting the variables within the script itself is more for neatness and convenience. I would be using a lot of different scripts doing different things but each would be using these same variables and I didn't want the first 50 lines of each script to always be variable declarations.

Based on what I've found from forums, I have tried the following

`cat declarevars.txt'

and

foreach line ("`cat declarevars.txt`")
end

However, none of these seem to work. I am hoping that someone can help me with this question. Thank you very much!

If it is in csh syntax you can include it with the source command

# for safety turn wildcard globbing off
set noglob
source declarevars.txt
unset noglob
1 Like

Thank you very much, MadeInGermany! It works now. :smiley: