Io

fs_read_file

Read an entire file to stdout with error handling.

Arguments

  • $1 (string): Path to the file

Exit codes

  • 0: Success
  • 1: File not found or not readable

Output on stdout

  • File contents

fs_write_file

Write content to a file, creating parent directories as needed. Content may be supplied as a second argument or piped via stdin. The file is created or overwritten.

Arguments

  • $1 (string): Path to the file
  • $2 (string): Optional: content to write (if omitted, reads from stdin)

Exit codes

  • 0: Success
  • 1: Path is a directory, or parent directory could not be created

fs_append_line

Append a line to a file if it is not already present (idempotent). Creates the file and parent directories if they do not exist.

Arguments

  • $1 (string): Path to the file
  • $2 (string): Line to append

Exit codes

  • 0: Success (line added or already present)
  • 1: Missing arguments, or parent directory could not be created

fs_read_lines

Read a file into an indexed array, one element per line. Blank lines and lines beginning with # are included as-is. Defaults to FS_LINES as the target array name.

Example

fs_read_lines /etc/hosts
printf '%s\n' "${FS_LINES[@]}"

Arguments

  • $1 (string): Optional: '-n ' to specify target array name
  • $2 (string): Path to the file (or $1 if -n not used)

Exit codes

  • 0: Success
  • 1: File not found or not readable

fs_temp_register

Register one or more paths for automatic cleanup by fs_temp_cleanup.

Arguments

  • ... (string): One or more file or directory paths to register

Exit codes

  • 0: Always

fs_temp_predictable_file

Create a predictable PID-scoped temporary file and register it for cleanup. Because the path is derived from the current PID, it can be reconstructed inside trap callbacks without passing the path through variables.

Arguments

  • $1 (string): Base name for the file (e.g. "myapp-config")
  • $2 (string): Optional suffix (e.g. ".json")

Exit codes

  • 0: Success
  • 1: A directory already exists at the generated path

Output on stdout

  • Full path to the created file

fs_temp_predictable_dir

Create a predictable PID-scoped temporary directory and register it for cleanup. Because the path is derived from the current PID, it can be reconstructed inside trap callbacks without passing the path through variables.

Arguments

  • $1 (string): Base name for the directory (e.g. "myapp-work")
  • $2 (string): Optional suffix

Exit codes

  • 0: Success
  • 1: A file already exists at the generated path

Output on stdout

  • Full path to the created directory

fs_temp_cleanup

Remove all paths registered via fs_temp_register, then remove the manifest.

Exit codes

  • 0: Always

fs_temp_exit

Register fs_temp_cleanup to run when the process exits normally (INT, TERM, QUIT, EXIT, HUP). Does not cover ABRT; use fs_temp_abort for that.

Exit codes

  • 0: Always

fs_temp_abort

Register fs_temp_cleanup to run when the process receives ABRT. Use alongside fs_temp_exit to cover all common exit paths.

Exit codes

  • 0: Always