function infolog() {
local prefix_text="[INFO]"
local input=$@
# Check if input is from a pipe
if [[ -p /dev/stdin ]]; then
while IFS= read -r line; do
echo -e "${prefix_text} ${line}"
done
else
echo -e "${prefix_text} ${input}"
fi
}
$ ls | infolog
[INFO] file1
[INFO] file2
[INFO] file3
$ infolog Hello, world!
[INFO] Hello, world!