0

user-home-list.sh is a simple bash script that returns the list of home directories for the users.

Now here is the weird thing:

$ A=$(./user-home-list.sh | md5sum)
$ echo $A
ddd1450681209aa2ede8696789300aa1 -
$ ./user-home-list.sh | md5sum
ddd1450681209aa2ede8696789300aa1  -

Notice the additional space before - in the output of the last command. Any clue why this is happening?

Cyrus
  • 77,979
  • 13
  • 71
  • 125
rockoder
  • 747
  • 10
  • 22
  • 7
    The issue is in `echo $A` instead of `echo "$A"`. When unquoted, variable expansion does word splitting and globbing. Word splitting causes multiple spaces to squeeze into one. – Léa Gris Jan 15 '22 at 18:03

0 Answers0