简体   繁体   中英

export variable to linux using shell script

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???

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM