Skip to main content
Post Undeleted by Stéphane Chazelas
added 9 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

$ echo 323 | openssl dgst -sha1 -binary | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0                                       |cK7.|
00000014

See how that contains both a 0 byte and newline character (0xa)

$ echo 323 | openssl dgst -sha1 -binary | IFS= LC_ALL=C read -ru0 -k20 var &&
  var=${var}World
$ printf %s $var | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0 57 6f 72 6c  64                       |cK7.World|
00000019

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

$ echo 323 | openssl dgst -sha1 -binary | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0                                       |cK7.|
00000014

See how that contains both a 0 byte and newline character (0xa)

$ echo 323 | openssl dgst -sha1 -binary | IFS= read -ru0 -k20 var &&
  var=${var}World
$ printf %s $var | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0 57 6f 72 6c  64                       |cK7.World|
00000019

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

$ echo 323 | openssl dgst -sha1 -binary | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0                                       |cK7.|
00000014

See how that contains both a 0 byte and newline character (0xa)

$ echo 323 | openssl dgst -sha1 -binary | IFS= LC_ALL=C read -ru0 -k20 var &&
  var=${var}World
$ printf %s $var | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0 57 6f 72 6c  64                       |cK7.World|
00000019

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.

Post Deleted by Stéphane Chazelas
added 499 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

$ echo 323 | openssl dgst -sha1 -binary | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0                                       |cK7.|
00000014

See how that contains both a 0 byte and newline character (0xa)

$ echo 323 | openssl dgst -sha1 -binary | IFS= read -ru0 -k20 var &&
  var=${var}World
$ printf %s $var | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0 57 6f 72 6c  64                       |cK7.World|
00000019

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

echo 323 | openssl dgst -sha1 -binary | IFS= read -ru0 -k20 var &&
  var=${var}World

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

$ echo 323 | openssl dgst -sha1 -binary | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0                                       |cK7.|
00000014

See how that contains both a 0 byte and newline character (0xa)

$ echo 323 | openssl dgst -sha1 -binary | IFS= read -ru0 -k20 var &&
  var=${var}World
$ printf %s $var | hd
00000000  3a 8b 03 4a 5d 00 e9 07  b2 9e 0a 61 b3 54 db 45  |:..J]......a.T.E|
00000010  63 4b 37 b0 57 6f 72 6c  64                       |cK7.World|
00000019

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.

Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

You can't store binary data (binary data generally refers to data with arbitrary byte values, not only byte values that form valid characters but is not special otherwise) in bash variables as bash doesn't support storing the 0 byte value in its variables (and remember you can't pass such strings in arguments to commands as those are NUL delimited strings).

You can in zsh though. Also remember that command substitution strips trailing newline characters (0xa bytes, maybe different on Cygwin), so it's probably better to use read here:

echo 323 | openssl dgst -sha1 -binary | IFS= read -ru0 -k20 var &&
  var=${var}World

Note again that you can only pass that variable to builtin commands (printf...).

Now, if all you want is hash it again, then it's just

(echo 323 | openssl dgst -sha1 -binary; printf %s World) |
  openssl dgst -sha1 -binary

no need for a variable.