Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • It may be fun to perform variable assignments using the conditional operator but it'd make your code highly unreadable. I'd prefer ((a)) && b=1 || c=1 Commented Apr 27, 2014 at 8:34
  • @devnull I think the code's readability depends most upon who reads it. Still, it may be true what you say, but I've tested ternary operators in dash, zsh, sh, and bash and they all behave the same, despite their not being specified by POSIX. Your example only works in bash and zsh as far as I know. However, this is POSIX friendly: ( : ${a?} ) && b=1 || c=1. I also find it far easier to read than either ternary or your own example. Commented Apr 27, 2014 at 13:05