I have a bash script, where the psql connect string is stored in a variable.
After this I have defined three functions. —————————
export PC="usr/bin/psql --host=abx --port=1234 --dbname=A --username=user"
function one
{
$PC<<EOF
SEL 1;
EOF
}
function two
{
while IFS= read -r line
do
three $line
done < file
}
function three
{
if [ $1 == Y ]
then
$PC<<EOF
Update table;
EOF
fi
}
#main function
one
two
————————
When I execute the script, function one
works, retrieves data from the database, but function three
invoked from function two
keeps failing with the message
bash: psql -u …($PC expanded): command not found
I have checked both the PATH
variable and IFS
, no issues there.
Now, if I use the expanded $PC
inside the function three
definition, then it works.
So only when I use a variable it fails? Any ideas?