1
LINE="a    b"
echo $LINE

when I run this sh file, I get this output:

a b

I actually want to process a BAI2 file where spaces and indexes need to be accurate. I loop over each line and echo $line >> "${FILE}". So I need all the spaces in the line to be printed as it is. Please help me what I can do to solve this.

codeforester
  • 39,467
  • 16
  • 112
  • 140
user2511270
  • 31
  • 1
  • 2

1 Answers1

5

Quote your variables!

echo "$LINE"

Otherwise, word splitting is performed and echo sees two arguments a and b, rather than one argument "a b". Try with set -x to see the difference.

Community
  • 1
  • 1
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141