Reputation: 69
I want to export variables to linux using shell script. My shell scrip is as following:
export dbHost=server01
export dbName=someName
when I print these variable after running script I get the following output
"eclare -x dbHost=" server01
declare -x dbName=" someName "
So it correctly exports the dbName but not dbHost. If I keep only the first line
export dbHost=server01
in the script then it prints dbHost correctly. What am I doing wrong here???
Upvotes: 1
Views: 506
Reputation: 786291
I suspect you have DOS line ending in your file that you can test with:
cat -t file.sh
That will show something like this:
export dbHost=server01^M
export dbName=someName^M
To fix this issue run dos2unix
on your file.sh
.
Upvotes: 1
Reputation: 14169
when I print these variable after running script
The variables you export
will only be visible inside the shell your script runs in and in subshells. If you want to see the effects after your script terminates, you have to source
your script.
An explanation can be found in answers to this question on superuser.
Upvotes: 0