1

I have the following script:

foo="foo";
bar="bar";
separator=": ";
result="${foo}${separator}${bar}";
echo $result;

I expected to get foo: bar, but the output was foo:bar - the space was lost. What am I missing here?

Here is the code of the alias inside .gitconfig:

[alias]
    vx = "!f() { foo="foo"; \
              bar="bar"; \
              separator=": "; \
              result="${foo}${separator}${bar}"; \
              echo $result; \
             }; f" 

P.S. I also tried result=${foo}${separator}${bar}; without double quotes - didn't work either. P.P.S. I should note that this script is running in the confines of a .gitconfig alias.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • 2
    Changing `separator=": "` to `separator=': '` seems to work. Apparently git consumes double quotes. – oguz ismail Feb 04 '21 at 07:28
  • @oguzismail Thank you. I would have never occurred to me. – AngryHacker Feb 04 '21 at 07:29
  • 1
    There's more information on how git's config parser works [here](https://stackoverflow.com/questions/56015130/why-does-quoting-arguments-not-do-anything-in-git-aliases). – oguz ismail Feb 04 '21 at 07:32
  • 2
    You should always be worried when using quotes inside those same quotes. It's hard for languages to know that `"!f() { foo="` isn't a complete string – that other guy Feb 04 '21 at 07:33
  • 2
    Double quotes in double quotes doe not work. You just "unquote" the sentence and the white space will be removed. Running the first code block in my terminal works just fine. – Bayou Feb 04 '21 at 07:42

0 Answers0