The problem is that ;
is treated as a control operator, and the string BS_DATABASE_CONNECTION=connection;Data Source=source;...
is interpreted as multiple commands. The first is the command BS_DATABASE_CONNECTION=connection
, the second is the command Data Source=source
, etc. One solution is to use quotes:
BS_DATABASE_CONNECTION='connection;Data Source=source;Initial Catalog=catalog;Persist Security Info=info;User ID=userid;Password=password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;'
But with a value this long, it would probably be more readable to do something like:
BS_DATABASE_CONNECTION="\
connection;\
Data Source=source;\
Initial Catalog=catalog;\
Persist Security Info=info;\
User ID=userid;\
Password=password;\
MultipleActiveResultSets=False;\
Encrypt=True;\
TrustServerCertificate=False;\
"
or
BS_DATABASE_CONNECTION=''
for x in 'connection' \
'Data Source=source' \
'Initial Catalog=catalog' \
'Persist Security Info=info' \
'User ID=userid' \
'Password=password' \
'MultipleActiveResultSets=False' \
'Encrypt=True' \
'TrustServerCertificate=False' \
; do
BS_DATABASE_CONNECTION="${BS_DATABASE_CONNECTION}${x};"
done
or
read BS_DATABASE_CONNECTION << EOF
connection;\
Data Source=source;\
Initial Catalog=catalog;\
Persist Security Info=info;\
User ID=userid;\
Password=password;\
MultipleActiveResultSets=False;\
Encrypt=True;\
TrustServerCertificate=False;
EOF
or
BS_DATABASE_CONNECTION=$( tr \\n \; << EOF
connection
Data Source=source
Initial Catalog=catalog
Persist Security Info=info
User ID=userid
Password=password
MultipleActiveResultSets=False
Encrypt=True
TrustServerCertificate=False
EOF
)
Note that this is not an environment variable. It is merely a shell variable. If you want it to be in the environment of subshells, you should export it. Whether it is in the environment of the shell or not should be completely irrelevant, and there is no functional difference between an environment variable and an exported shell variable.