#!/bin/bash
name="rebom"
version="1.1"
read -r -d '' help_message <<-EOF
Add BOM to a target file
Usage: rebom TARGET [OPTIONS]
Options:
-h, --help print this message
-q, --quiet suppress error messages and prompts
-v, --verbose show additional messages
-V, --version print version number and exit
EOF
source /usr/local/lib/mylib.bash
positional=()
quiet=0
verbose=0
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
help_msg
shift
;;
-q|--quiet)
debug_msg "Setting quiet option to 1 (was ${quiet})"
quiet=1
shift
;;
-v|--verbose)
debug_msg "Setting verbose option to 1 (was ${verbose})"
verbose=1
shift
;;
-V|--version)
version_msg
shift
;;
*)
debug_msg "Argument '${1}' added to positional array"
positional+=("$1")
shift
;;
esac
done
# error if no filenames given
if [[ ${#positional[@]} -eq 0 ]]; then
usage_msg
fi
code=0
files=()
for filename in "${positional[@]}"; do
if [ ! -f "$filename" ]; then
nonfatal_error_msg "No such file '$filename'"
code=1
else
files+=("$filename")
fi
done
# error if no valid filenames given
if [[ ${#files[@]} -eq 0 ]]; then
exit 1
fi
/usr/bin/printf "\xEF\xBB\xBF"
/usr/bin/cat ${files[@]}
exit "$code"