You're welcome; I just thought it would add a little perspective of how this concept can be used in various ways. Some might always prefer to use if/else statements to be safe & sometimes it is necessary, but I find myself using this type of 'shortcut' more times than not when it's safe to use.
Been using UNIX since the late 80s; Linux since the mid-90s; virtualization since the early 2000s and spent the past few years working in the cloud space.
Location
Alexandria, VA, USA
Education
B.S. Psychology from Pennsylvania State University
Ternary (or more) operations on a single line:
And can be multiple lines:
Nice 👍 thanks for the add-up, Ian
You're welcome; I just thought it would add a little perspective of how this concept can be used in various ways. Some might always prefer to use if/else statements to be safe & sometimes it is necessary, but I find myself using this type of 'shortcut' more times than not when it's safe to use.
I use the
<CMD> && <SUCCESS_ACTION> || <FAIL_ACTION>
method quite a lot ...annoying that BASH-linters complain about it.Thanks for these examples, they are really helpful