2

Can anyone tell me why the following:

#!/bin/bash
TEST=$(echo '*** this is a test ***')
echo $TEST

...outputs a listing of the current directory, then "this is a test", then another listing of the current directory?

Background: I have some output that I'm putting in a variable, and then I want to do several different greps on the contents of that variable, but the echo is inserting all this extra stuff that shouldn't be there.

This is on OS X 10.11.4.

T. Reed
  • 181
  • 1
  • 9

1 Answers1

2

globbing in action! * expands in the second echo. You have to double quote it to prevent expansion.

echo "$TEST"

see this for a related answer

Community
  • 1
  • 1
karakfa
  • 66,216
  • 7
  • 41
  • 56