How to convert this statement to use the ternary operator ( ? : )

How can I convert the below shell script text snippet to use a ternary operator.  I read at that Linux does support a ternary operator, but I'm having trouble figuring out how to do it.

I know if this was Javascript, I could do:

   EXISTS=(text=="Apple") ? "Passed" : "Failed";

But because of the quirky syntax of Linux, I'm not sure how to convert it.
if [ $text = "Apple" ];

Open in new window

LVL 13
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

in bash?

[ "$var" = "Apple" ] && EXISTS="Passed" || EXISTS="Failed"

if [ $text = "Apple" ];
always returns true, isn't it?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Linux doesn't support any ternary operator, I think you mean the Bourne shell (/bin/bash)
to get consistent behavior, you need to know which shell you are using, so good shell scripting
design always starts by specifying which interpreter (/bin/sh, /bin/csh, /bin/ksh, /bin/bash, /bin/tcsh, /bin/perl)
to use.

And ravenol's solution is correct

# Rest if script follows...

Open in new window

jrramAuthor Commented:
Yes, it will always be true...that was a bad example.... but your solution worked.

Its a little different since you have to use the EXISTS= statement twice.  But it works.
jrramAuthor Commented:
I'm using the Bash shell.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.