Reputation: 1832
My script
#!/bin/bash
set -eu
usrFile="${1}"
while read -r usrCMD
do exec -e "${usrCMD}" || echo_fun "${usrCMD}"
done < "$usrFile"
echo_fun is a function that prints the message.
In the echo_fun, I want to pass the error message of command exec -e "${usrCMD}"
Is this possible?
Upvotes: 0
Views: 216
Reputation: 782444
Assign stdout
to a variable, as explained in How to store standard error in a variable
Then pass that variable to echo_fun
while read -r usrCMD; do
error=$(exec -e "$usrCMD" 2>&1 >/dev/null) || echo_fun "$usrCMD $error"
done < "$usrFile"
Upvotes: 1