The following functions perform actions that can normally be done directly with the redirection operators of Bash:
# write to a file printf '%s' "$string" >"$filename" # append to a file printf '%s' "$string" >>"$filename" # read a file, print contents printf '%s' "$(<$filename)"
The functions act differently in that they spawn a bash
subprocess, by invoking
mbfl_program_bash_command()
, and let it do the operation; this allows us to request the use of
sudo
and so to read and write files with modified privileges, but only for the time needed
to do the operation, not for the whole script. Executing a
bash
process.
Write STRING to FILENAME, eventually creating it or overwriting old contents.
Append STRING to FILENAME, eventually creating it.
Read and print all the contents of FILENAME.
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.