LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-29-2010, 08:55 AM   #1
logicalfuzz
Member
 
Registered: Aug 2005
Distribution: Arch Linux
Posts: 291

Rep: Reputation: 48
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)

Last edited by logicalfuzz; 01-29-2010 at 08:56 AM.
 
Old 01-29-2010, 09:05 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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....
 
Old 01-29-2010, 09:19 AM   #3
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
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`
 
Old 01-29-2010, 09:26 AM   #4
logicalfuzz
Member
 
Registered: Aug 2005
Distribution: Arch Linux
Posts: 291

Original Poster
Rep: Reputation: 48
Quote:
Originally Posted by rn_ View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script (iptables) syntax error mrmnemo Programming 6 12-04-2009 08:57 AM
why is my shell script giving me - syntax error near unexpected token 'enterInfo() chisunum Linux - Newbie 3 10-23-2009 03:37 PM
Shell script syntax question arash8m Programming 4 06-01-2007 08:39 AM
shell script help required syntax error sridhar11 Programming 1 10-31-2005 08:38 AM
Shell Script Syntax dragon49 Programming 1 03-12-2003 09:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration