Question

I am fairly inexperienced with shell(csh in this case) scripts but was asked to edit one. I was asked to add a config file to make it much simpler to edit several specific variables. I thought this was silly because this is a script and reading to and from a file would be a little silly so I though I could just make a different script that would set the variables.

The parent script

#!/bin/csh
...
...

./set_vars

echo $aVar

and my set_vars script looks something like

#!/bin/csh

setenv aVar "400"
echo $aVar

But aVar i snot defined in the parent script.

my question becomes... how do I make the child script set variables that the parent script can use, Or is there a better way to have a config file where someone can set variables.

This seems like a silly way to do it but the best way I can tell that doesnt require any file IO and still has a concise file to edit vars in.

Was it helpful?

Solution

You should execute the "set_vars" script within the context of its parent. In C-shell, you achieve this with the "source" command :

#!/bin/csh
...
source set_vars
...
echo $aVar
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top