I want to conditionally submit a text into another shell script. Meaning I want to replace "WARNING" in case deb=1 with "INFO":
#!/usr/bin/env bash
...
if [[ $abc -lt 98 ]] || [[ $deb -eq 1 ]]
then
./discord.sh --webhook-url=$url --text "WARNING: $abc"
fi
I also want to avoid another complete IF statement. I expect to have something like
deb=1 ? "INFO" : "WARNING"
Does that work? If yes, how would the complete statement look like? "–text …"
Thank you in advance.
4
Answers
You mean something like this?
Think of this as a alternative to
if
then
else
fi
(the curly brackets are only neccesary if you have more commands, but I like to use it anyway, for readability (in some cases).Basically it’s
[[ condition ]] && { commands if true } || { commands if false }
Would you please try:
Can be done with an array index to match a numerical log-level with a name string:
Output:
IMHO the answer of @tshiono is best. However, it becomes hard to read/debug.
Why not use a verbose solution?
When both conditions are true, you want to log with INFO.