Hi there, i think im getting myself a little confused and need some help :wall:
I am reading in a bunch of variables to my script from an external file and need to validate that a value has been set for each
so if you can imagine, the user is required to pass in 4 values username,password,uid and gid. these get set to
$USER
$PASS
$UID
$GID
now this is fine, however I want to write a little loop that tests for its existence and echos an error if its not set. I appreciate I can do this as individual lines, but in reality there are more than 4 variables, there are hundreds, so id like to do it in a loop
so the idea being something like
for i in "USER PASS UID GID"; do
if [ -z "$i" ] ; then
echo $you have not entered a value for $i"
exit 1
fi
done
now i realise that this wont work because when $i is expanded it is just a string and not another varuable, but ive tried
if [ -z "${$i}" ] ; then
and
if [ -z "$${i}" ] ; then
etc
would I need to use 'eval' and if so, can someone give me an example of how i would do this?
any help would be greatly appreciated