[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: CR/LF



On Sat, Dec 10, 2022 at 08:35:59PM -0600, David Wright wrote:
> On Sat 10 Dec 2022 at 21:01:29 (-0500), Jim Popovitch wrote:
> > Why does this produce a CR/LF
> > 
> >  ~$ TEST=$(ssh -o LogLevel=QUIET -t user@server "echo -n ''"); echo ${TEST}
> 
> Try echo -n ${TEST} at the end.

You mean printf %s "$TEST" or at least echo -n "$TEST".[1]

Without the quotes, you may potentially get a VERY different result from
what you expect.

And we haven't even got to the part where $() strips the trailing newline
since there hasn't been a trailing newline coming from the remote system
yet.  I'm waiting for the question to change, and then that one will be
relevant.

[1] Really, just stop using echo altogether, except with constant
arguments.  printf is the only way to guarantee the expected output
when variables are involved.


Reply to: