1

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?

Stav Alfi
  • 13,139
  • 23
  • 99
  • 171

2 Answers2

2

Consider using shell array for this:

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

then use it as:

yarn jest "${arr[@]}"
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    the parsing will be `-t '2 2.1'` and not `-t "2 2.1"` but it is ok for me. – Stav Alfi Feb 17 '20 at 10:48
  • 1
    @StavAlfi: it is essentially. same. You can have array as: `arr=("-t" "2 2.1")` also. – anubhava Feb 17 '20 at 10:50
  • 1
    @StavAlfi : Both All of `'2 2.1'`, `"2 2.1"` and `2\ 2.1` denote the exactly same 5-character string (consisting of 2, space, 2, period and 1). Where do you see any difference? – user1934428 Feb 17 '20 at 12:28
0

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

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

Hope this helps

Tarique
  • 1,273
  • 9
  • 15