Reputation: 186
I've been reading the Advanced Bash Scripting Guide trying to learn more about what is considered best practice and came across this way of constructing conditionals:
#condition?result-if-true:result-if-false
(( var0 = var1<98?9:21 ))
# ^ ^
# if [ "$var1" -lt 98 ]
# then
# var0=9
# else
# var0=21
# fi
It looks cool but is there an advantage to this outside of how compact it is?
Upvotes: 1
Views: 87
Reputation: 364
It may look cool in geeky eyes, but it's difficult to read. There is no advantage to this. So stick to if-then-else or put a lot of comments on it just like you did in your question.
Upvotes: 2