Stav Alfi
Stav Alfi

Reputation: 13953

bash variable with double-quotes

There is an exported env-variable X:

X="-t \"2 2.1\""

The following command is parsed wrong when using this variable:

yarn jest $X
yarn jest -t '"2' '2.1"'

Instead of:

yarn jest -t "2 2.1"

I have read a-lot of similar questions but none of them worked. Any help?

Upvotes: 1

Views: 209

Answers (2)

Tarique
Tarique

Reputation: 1461

Try using X="-t '2 2.1'"

Use single quotes inside double quotes instead of using double quotes twice.

Hope this helps

Upvotes: 0

anubhava
anubhava

Reputation: 786041

Consider using shell array for this:

arr=('-t' '2 2.1')

then use it as:

yarn jest "${arr[@]}"

Upvotes: 2

Related Questions