Shell: How to execute commands from another file?

I made a configuration file for my shell script in that all the values that the shell scipt needs, are defined, but I don't know how to let the shell script use those defined variables.

Thank you for your help :slight_smile:

Can you post how your configuration file looks like ?
and also a brief requirement list of your shell script .

Assuming you are using ksh or bash, and if your config file contains just shell assignment statement like

working_directory=/usr2/stuff/images
output_type=".png"
geometry="640x480"
qual=80

then you can source (sometimes called dotting in) the file. For instance, if the above exists in the file xxx.cfg in your bin directory, then the script(s) that need it can source it like this:

. ~/xxx.cfg

Sourcing a file (in Kshell or bash) causes the shell to open the named file and parse the contents as though they were a part of the script that it is executing. It is possible to put more than just assignment statements in the file being source; any valid shell statement can be included, but that's moving beyond the topic of this thread.

If your configuration file has a different format, or you are not using ksh, bash or a shell that supports sourcing like this, then as CodeManiac indicated please post more information.

Yes, sourcing worked! Thank you very much!
I prefer the classic shell to bash and ksh though... :slight_smile: