Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 1.59 KB

File metadata and controls

46 lines (27 loc) · 1.59 KB

cache-pipe

cache-pipe is designed to cache the output of a pipe command into a temporary file and then move that temporary file to overwrite the source of the pipe. This is particularly useful for operations that require atomic updates to files based on the output of a command.

Version

1.0.2

Synopsis

cache-pipe [options] [file]

Description

cache-pipe takes the output of a piped command and writes it to a temporary file. Once the command completes, the temporary file is moved to replace the original file specified as an argument. This ensures that the file update is atomic and reduces the risk of data corruption.

Options

  • -v, --version: Displays the version number of the cache-pipe function.
  • -h, --help: Shows the help message, including usage and options.

Examples

Caching the output of a simple echo command into a file named sample.txt:

echo 'Hello World' | cache-pipe sample.txt

After running the above command, you can display the contents of sample.txt to see the output:

cat sample.txt # => Hello World

Usage

To use cache-pipe, simply pipe the output of a command into cache-pipe followed by the target file name. The function will handle the creation of a temporary file, writing the piped output to this file, and then atomically moving the temporary file to overwrite the target file.

Notes

  • Ensure that the target file's directory exists, as cache-pipe does not create directories.

For more detailed examples and usage scenarios, refer to the Examples section.