3

I have a variables source file called my.vars located in ~/. In it I have:

FIRSTNAME=John
LASTNAME=Doe
FIRSTANDLASTNAME=John Doe

In a script I call the source file using:

. ~/my.vars

But I keep getting the error:

line 3: Doe: command not found

I read somewhere that the source command actually runs the program so it maybe seeing the space as a delimiter.

How can I call the variables source file in my script? I've tried also:

source ~/my.vars

Same result

4

The problem is that as you have a space in variable value, as a result the first part is being assigned as the variable value and the last part is being treated as a standalone command, leading to the error.

So the variable is being set as FIRSTANDLASTNAME=John and Doe is being taken as a command.

You need either quoting or escaping, any one of the following would do:

FIRSTANDLASTNAME="John Doe"
FIRSTANDLASTNAME='John Doe'
FIRSTANDLASTNAME=John\ Doe

Now you would be able to source (.) the file expectedly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.