LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   is there a '?:' syntax shell script? (https://www.linuxquestions.org/questions/linux-general-1/is-there-a-syntax-shell-script-785606/)

logicalfuzz 01-29-2010 08:55 AM

is there a '?:' syntax shell script?
 
This might be a quickie... but i am not able to understand the appropriate thing to put in the google search...

Is there a way to use the ?: operator for if-else decision in a shell script?

edit: the 'question mark - colon' operator
(just editing so that its searchable by someone in need :-P)

pixellany 01-29-2010 09:05 AM

For those who don't already know, please tell us what that operator does.

In an "if" construct, the branching is based on whether a statement evaluates to TRUE or FALSE. Thus you can use any operator you want, as long as you wind up with something that produces a true or false output.

Tell us what you are trying to do, and we can give better help....

rn_ 01-29-2010 09:19 AM

Are you referring to the C-style clause:
Code:

var = (condition) ? return-value-if-true : return-value-if-false
?

You can sort of emulate this behavior, like so:

Code:

myvar=`[[ condition ]] && echo return-value-if-true || echo return-value-if-false`

logicalfuzz 01-29-2010 09:26 AM

Quote:

Originally Posted by rn_ (Post 3844953)
Are you referring to the C-style clause:
Code:

var = (condition) ? return-value-if-true : return-value-if-false
?

You can sort of emulate this behavior, like so:

Code:

myvar=`[[ condition ]] && echo return-value-if-true || echo return-value-if-false`

hey yes.. i was refering to the c-style clause...
and thanks a lot mate! Thats precisely what i needed


All times are GMT -5. The time now is 10:19 AM.