0

TWO QUESTIONS:

  1. Is there a concise way strip the trailing \n of the stdin from version when using <<
  2. Is there a name for <<< that will help when searching for answers to questions like this? ('IFS' and 'three left angle brackets', etc, haven't been particularly stellar search terms.)

Detail

The following commands feed a trailing \n on MacOS Terminal:

Version A (using echo)

    echo SomeText | openssl dgst -sha512 -hex -hmac SomeHmacKey

Version B - (using <<<)

    openssl dgst -sha512 -hex -hmac SomeHmacKey <<< SomeText

The Results both Versions A & B are 858337c9909dccb8cb21293f057bd8aa1a90a5ea084b36825e28f8f6a2ef9d813a991dfa7d25fe4afd1f78004213a23dd4e71e05e4cea7f9ad4bf1c5adbd224a, which is the result for SomeText\n, as opposed to SomeText

To strip the trailing LF on Version A, I used the solution

    echo -n SomeText | openssl dgst -sha512 -hex -hmac SomeHmacKey

Is there a concise way strip the trailing \n of the stdin from version B (i.e. when using <<<)?

WhatsYourFunction
  • 621
  • 1
  • 9
  • 25

1 Answers1

2

<<, <<< and other such constructs are known as redirection operators.

<<< in particular is known as "here string". The fact that it adds a newline and the reason why is well documented here.

As to how to get around this problem, you already know a good way: just pipe echo -n SomeText instead of using a here string.

mnistic
  • 10,866
  • 2
  • 19
  • 33