1

If I execute

 git version
 mkdir test
 cd test
 touch a b c
 git init
 git add -A
 git commit -m "test"
 git branch -a
 ls
 x=$(git branch -a); echo $x

I get the following output:

git version 2.4.2
* master
a  b  c
a b c master

First line is the git version.
Second is the git branch -a.
Third line is output of ls.
Fourth line is the output of x=$(git branch -a); echo $x

This is weird. Shouldn't lines 2 and 4 be equal?

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
Timo
  • 1,724
  • 14
  • 36
  • 3
    Quote your use of `"$x"` and they will be. Unquoted the shell is expanding the `*` as a glob and listing all the files in the current directory. – Etan Reisner Jun 25 '15 at 16:39
  • See http://stackoverflow.com/q/24812464/258523 for another instance of this issue (and there are many more). – Etan Reisner Jun 25 '15 at 16:41
  • oh, how could I not see this. Thanks. Please mark the question as duplicate or add you answer as "Answer". – Timo Jun 25 '15 at 16:51
  • BTW, http://shellcheck.net/ (linked from the bash tag wiki) would have caught this one for you. :) – Charles Duffy Jun 25 '15 at 16:59
  • Yeah, that was the problem. I wasn't sure what to mark it a duplicate of exactly (which is a problem with a lot of the common shell issues). I sometimes wish I could mark things as duplicates of BasHFAQ entries or shellcheck warnings/wiki entries. =) – Etan Reisner Jun 25 '15 at 17:02

0 Answers0