0

trying to do the following:

echo "- - 830 "FTL  MFG" -"

the "FTL MFG" should be left alone as one entry.

what am I doing wrong?

2 Answers2

4
echo "- - 830 "FTL  MFG" -"
     ^^^^^^^^^^        ^^^^ quoted
               ^^^^^^^^ not quoted

echo sees two arguments: - - 830 FTL and MFG -, and prints them with a space in between. If you want an output with quotes, you need to escape them, or use single quotes to surround the string:

echo "- - 830 \"FTL  MFG\" -"
echo '- - 830 "FTL  MFG" -'
ilkkachu
  • 138,973
2

Double quotes " are string delimiters (and strings work differently in shells from what they do in most programming languages). Compare:

$ for a in "- - "830 FTL MFG" -"; do echo "$a"; done
- - 830
FTL
MFG -

You'll want to either escape the double quotes (so that they are interpreted as literal double quotes) or to delimit your string with ' instead.

%  echo "- - 830 \"FTL MFG\" -"
- - 830 "FTL MFG" -
% echo '- - 830 "FTL MFG" -'
- - 830 "FTL MFG" -
giorgiga
  • 143
  • Not that peculiar, you just stick strings together to concatenate them. – ilkkachu Jan 16 '18 at 16:57
  • Thanks @roaima: makes no difference in my example but indeed I ought to quote properly in a question about quoting :-) answer edited – giorgiga Jan 16 '18 at 17:42
  • Thanks @ilkkachu: I edited to better specify what I mean (which admittedly is not what I had written before) – giorgiga Jan 16 '18 at 17:56