append-once

From Kicksecure
Jump to navigation Jump to search

append-once is a shell utility that appends a line to a file only once. It is useful for scripts that need to modify configuration files or other persistent files without introducing duplicate lines.

Introduction[edit]

append-oncearchive.org iconarchive.today icon:

  • Appends once and is supposed to avoid duplicating the same content, should the exact same lines have already been appended earlier.
  • Includes additional sanity testing (checks if the folder where the file resides is writable; checks if the file is readable and writable).
  • Offers an easier-to-use interface. [1]
  • Write operations are atomic.
  • Its write operation is similar to:
printf "%s\n" "text to append" | sponge -a /file/to/append/to >/dev/null

Target Audience[edit]

If append-once is used in security critical context it should only be used by people capable of reviewing its relatively short and is simple source code.

Syntax[edit]

append-once /path/to/file 'line to append'

Example[edit]

Click = Copy Copied to clipboard! append-once ~/testfile 'some text here'

Exit Codes[edit]

  • 0: Success.
  • Non-Zero: Failure.

Limitations[edit]

  • Did not support multi-line (with empty lines) at time of writing. Test before use.

Footnotes[edit]

  1. [1] No need to use:
    • grep
    • considering special characters in grep
    • printf
    • pipe
    • >/dev/null redirection.
Notification image

We believe security software like Kicksecure needs to remain Open Source and independent. Would you help sustain and grow the project? Learn more about our 12 year success story and maybe DONATE!