{{Header}}
{{title|title=
append/append-once/overwrite
}}
{{#seo:
|description=The append
, append-once
, and overwrite
utilities safely append a line to a file. append
appends a line unconditionally, append-once
appends a line only if the line isn't present in the file already, and overwrite
overwrites the entire contents of the file with the provided line. The scripts feature sanity checks, atomic write operations, and a simplified interface.
}}
{{intro|
How to use the append
, append-once
, and overwrite
to append and replace data in files.
}}
= Introduction =
[https://github.com/Kicksecure/helper-scripts/blob/master/usr/bin/append append
]:
* Appends a user-provided line to a text file.
* 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] No need to use:
* grep
* considering special characters in grep
* printf
* pipe
* readlink
* >/dev/null
redirection.
* Write operations are atomic.
* If called as append-once
, it avoids duplicating the same content, should the exact same lines have already been appended earlier.append-once
was previously implemented as a standalone Bash script, while append
and overwrite
did not exist. The new implementation is written in Python, fixes limitations, improves error and edge case handling, and provides the two additional utilities.
* If called as overwrite
, replaces all of the contents of the file with the provided line.
* Its write operation is similar to:
printf "%s\n" "text to append" | sponge -a /file/to/append/to >/dev/null
append
is the primary executable. The append-once
and overwrite
executables are simply symlinks to append
. append
will check what executable it was called as, and adjust its behavior accordingly.
= Target Audience =
{{AdvancedUsersOnly}}
If append
, append-once
, or overwrite
are used in a security critical context, it should only be used by people capable of reviewing its relatively short and simple source code.
= Syntax =
(append|append-once|overwrite) /path/to/file 'line to append'= Example = {{CodeSelect|code= append ~/testfile 'some text here' }} = Exit Codes = * 0: Success. * Non-Zero: Failure. = Limitations = * None known at the time of this writing. = Footnotes =