1

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

1
  • @anubhava by typing this command ". ./fileName.sh" (without quotes) Commented Feb 23, 2015 at 14:16

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Anubhava, that was the problem
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.