I need help sending the output (stdin and stdout) from system commands to a bash function, while still accepting input from arguments. Something like the example that follow
It's an old thread.. but I have used it to help me write a log function that will output also multiple lines of a command output:
# Defines function to grab a time stamp #
get_Time () { Time=$(date +%Y-%m-%d\ %H:%M:%S) ; }
write_Log()
{
get_Time
if [ -n "${1}" ]; then # If it's from a "" then set it
IN="${1}"
echo "${Time} ${IN}" | tee -a ${log_File}
else
while read IN # If it is output from command then loop it
do
echo "${Time} ${IN}" | tee -a ${log_File}
done
fi
}