5

Using this lz4 command:

$ apt search ^lz4$
Sorting... Done
Full Text Search... Done
lz4/focal,now 1.9.2-2 amd64 [installed,automatic]
  Fast LZ compression algorithm library - tool

$ lz4 --version
*** LZ4 command line interface 64-bits v1.9.2, by Yann Collet ***

This command normally creates a filename.lz4 file (just like gzip does):

$ lz4 -9 -k filename

However, this command does not, and instead writes to stdout when I'm not telling it to:

$ t=$(lz4 -9 -k filename)
Warning : using stdout as default output. Do not rely on this behavior: use explicit `-c` instead ! 
bash: warning: command substitution: ignored null byte in input

Why is it doing this? Is it a bug, or is there a reason documented somewhere?

1 Answer 1

4

The behaviour appears to be a feature - not a bug. I can't find it documented anywhere except in the source code:

/* No output filename ==> try to select one automatically (when possible) */
while ((!output_filename) && (multiple_inputs==0)) {
    if (!IS_CONSOLE(stdout)) {
        /* Default to stdout whenever stdout is not the console.
         * Note : this policy may change in the future, therefore don't rely on it !
         * To ensure `stdout` is explicitly selected, use `-c` command flag.
         * Conversely, to ensure output will not become `stdout`, use `-m` command flag */
        DISPLAYLEVEL(1, "Warning : using stdout as default output. Do not rely on this behavior: use explicit `-c` instead ! \n");
        output_filename=stdoutmark;
        break;
        .
        .
}

On Linux, IS_CONSOLE uses isatty to determine whether file desscriptors are connected to a terminal.

As suggested in the comment, you can use the -m option to force generation of an output file in cases where there is no tty:

t=$(lz4 -9 -k -m filename)
1
  • Thanks, good investigation and outcome.
    – k314159
    Mar 10, 2021 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.