I have a bash script where I can pipe in output from another application into the below script. But I think I have an incorrect logic for testing if the message is empty or not. If its empty I want it to do nothing, but if it detects the word "error" in the string, it should run another function.
What am I doing wrong in my logic?
I'm getting too many arguments on the 3rd to the last line, most likely due to the message being empty.
message=$( cat )
if [ -n "${message// /}" ]; then
#execute if the the variable is not empty and contains non space characters
message="\`\`\` ${message} \`\`\`"
else
#execute if the variable is empty or contains only spaces
message=""
fi
sendX() {
.....
}
if [ -z "$message" ]; then
echo "Please pipe a message to me!"
else
sendX
fi
sendAlert() {
......
}
checkword="error"
echo $message
if [ $message =~ $checkword ]; then <---- Error: too many arguments
sendY
fi