stdin into zip command, how do I specify a file name? [duplicate] stdin into zip command, how do I specify a file name? [duplicate] linux linux

stdin into zip command, how do I specify a file name? [duplicate]


What you can do is pipe the file in normally, then rename it in the zip

echo 'foo bar' | zip  > file.zipprintf "@ -\n@=filename.txt\n" | zipnote -w file.zip


Use a fifo (a named pipe) instead of piping stdin directly!

mkfifo text.txt               # create fifoecho 'foo bar' > text.txt &   # pipe data to fifo, in backgroundzip --fifo file.zip text.txt  # note the `--fifo` argument to ziprm text.txt                   # cleanup

Result:

$ unzip -l file.zipArchive:  file.zipLength      Date    Time    Name---------  ---------- -----   ----8          2020-11-29 12:30   text.txt---------                     -------8                             1 file

Note that the fifo is a named pipe. Just like the anonymous pipe - the famous | - no data is stored on your hard drive, it is streamed directly from writer to reader.


Write echo output to the desired filename, then use the -m flag to zip and remove the original file in one step.

echo 'foo bar' > filename.txt && zip -m filename.txt.zip filename.txt