Sourcing variables from another script

My manager required that i keep the hostnames and username and password in a separate file when creating my sftp script.
(Don't mention passwords and sftp...I've talk to him about this several times)

I have a list of hostnames that have to be read in a loop in my main script.

I don't know how to list these in the other file which contains ALOT of other variables, so that they will be picked up and read in a loop.

How do I do this?

create a file say, var.cfg

VAR1=variable1
VAR2=variable2

Now in script,

#/bin/sh

. ./var.cfg #or whatever the absolute path is

echo $VAR1
echo $VAR2

This should help!

I have four hostnames. All four are going to be used in this loop its pulling files from one server, then the next, then the next, and so on till it complete.

This file he wants the names in...contains about hundred variables used by many scripts. I

I dont know much about doing this, its my first time. I need to be spoke to like the idiot I am. How do I make sure these hostnames are read properly when I source them.

I know how to source the file, I know how to say pass=${PASSWORD_COMING_FROM_OTHER_sh} or whatever. But I dont know how to list them in this file so that they are read correctly.

Like I know I have to add an EXPORT HOSTS SECTION to it, then export the hosts to a variable array and then use that array in your script

But I have no idea how to do that.

Variables in sourced scripts work exactly the same was as variables everywhere else.

How do you make sure? Blank them before you load the file, then check if they are still blank.

die() {
        echo "$@" >&2
        exit 1
}

VAR1="" ; VAR2="" ; VAR3=""; VAR4=""

. configfile

[ -z "$VAR1" ] && die "VAR1 blank"
[ -z "$VAR2" ] && die "VAR2 blank"
[ -z "$VAR3" ] && die "VAR3 blank"
[ -z "$VAR4" ] && die "VAR4 blank"

If you have bash you can do this in a loop:

for VAR in VAR1 VAR2 VAR3 VAR4
do
        [ -z "${!VAR}" ] && die "$VAR blank"
done

I don't know what you mean by an EXPORT HOSTS SECTION.