The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 01:14 PM
AWK - conditional cause Rafael.Buria Shell Programming and Scripting 2 01-28-2008 01:24 PM
quoting in conditional statement 3Gmobile Shell Programming and Scripting 2 08-14-2006 03:14 AM
awk conditional statement 3Gmobile Shell Programming and Scripting 10 08-09-2006 10:01 AM
more elegant way for conditional statement needed candyflip2000 Shell Programming and Scripting 3 05-18-2006 07:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-19-2007
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
conditional statement

Hi
Does Unix have a conditional statement like Java as follows:
Condition ? Statement1 : Statement2

Thanks
  #2 (permalink)  
Old 08-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by lalelle View Post
Does Unix have...
UNIX can run C, C++, Fortran, Java, Scripts, Perl, Python, Pascal, COBAL etc, so yes it can.
  #3 (permalink)  
Old 08-19-2007
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
Sorry I meant shell script.

Basically, I want to do:
[ `echo "abcd" | cut -c1` = "a" ] && echo "a" ? echo "b"

Normally, it is a good idea or not to put a command in a test operation.
For instance, [ `echo "abcd" | cut -c1` = "a" ]

If not what else I can do.

Thank you
  #4 (permalink)  
Old 08-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
if ... then ... fi

case ... in ..... esac

all that a ? b : c does is if a then result is b else it's c.
  #5 (permalink)  
Old 08-19-2007
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
I know about if or case statement. I am just wondering that i can make it short in one sentence like

[ `echo "abcd" | cut -c1` = "a" ] && echo "a" : echo "b"

By the way thanks so much
I am now assuming that there is not any.
  #6 (permalink)  
Old 08-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
If it's any consolation, "x ? y : z" almost didn't get into the Java language.

Basically it's not needed.

It's main advantage in C is for complex macro expansion such as va_arg etc.
  #7 (permalink)  
Old 08-20-2007
fazliturk fazliturk is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 45
Quote:
Originally Posted by lalelle View Post
I know about if or case statement. I am just wondering that i can make it short in one sentence like

[ `echo "abcd" | cut -c1` = "a" ] && echo "a" : echo "b"

By the way thanks so much
I am now assuming that there is not any.
[ `echo "abcd" | cut -c1` = "a" ] && echo "a" || echo "b"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0