hermit.crab
hermit.crab

Reputation: 962

How does bash interpret embedded quotation marks in an expression?

Given this bash statement:

config_file=""$(dirname "$0")"/config.sh"

Is the expression interpreted as:

"" + $(dirname "$0") + "/config.sh"

or as:

"$(dirname "$0")"/config.sh

What should be the "proper" way of writing the expression/statement?

Upvotes: 1

Views: 29

Answers (1)

John Kugelman
John Kugelman

Reputation: 361645

It's the first one. You can jump in and out of quotes within the same word and all the adjacent pieces are concatenated.

The leading "" is removed, and the trailing "/config.sh" is equivalent to an unquoted /config.sh since it contains no special characters. The whole thing is therefore the same as:

config_file=$(dirname "$0")/config.sh

Upvotes: 2

Related Questions