On Sun, Dec 11, 2022 at 08:54:27AM -0500, Greg Wooledge wrote: > On Sun, Dec 11, 2022 at 08:16:35AM +0100, to...@tuxteam.de wrote: > > That said. Greg, I was also shaken by your roaring tone. > > Yeah, well, he was told the same thing, repeatedly, by multiple people, > and somehow he managed to ignore every single instance of it. > > It's rather frustrating.
I understand. Still yelling at people detracts from your extremely valuable contributions here. I would consider myself as a reasonably experienced shell programmer, and still learn from you time and again, so thanks for this. > As a formal statement for anyone else who's reading this, who might > actually listen: > > > echo ${TEST} does NOT show the contents of the TEST variable reliably. > > > For the following reasons: > > 1) ${TEST} is not a substitute for "$TEST". They do not mean the same > thing. You MUST double-quote the variable when you expand it, or > else the contents will undergo word splitting and pathname expansions. > > There are specific cases where the double-quotes may be omitted, but > until you know what those cases are, it's best to use the quotes > every time. This is not one of those cases. To illustrate: in my home directory tomas@trotzki:~$ FOO='key* hi* ho*' tomas@trotzki:~$ echo ${FOO} => keys.out keys1.out hill.scad holidays hours Needles to say: in your home directory, results may be different :) > 2) echo may interpret the content of TEST as an option (-n or -e), or it > may interpret backslash sequences inside the content, depending on > which shell you're using, and which platform you're on. > > The use of echo with variable arguments is therefore strongly > discouraged. Again, illustration: tomas@tritzki:~$ TEST="-n o n o" tomas@trotzki:~$ echo ${TEST} => o n o (with no newline at its end) > 3) echo usually, but not always, adds an additional newline character to > the output. In most cases, this is acceptable, even preferable. But > when the OP is complaining of an "extra CR/LF" [sic], but is using > echo to produce the extra newline himself, well... there you have it. Now which cases, besides when the -n option is given (I don't know, off the bat, I must admit). (more useful advice)
signature.asc
Description: PGP signature