LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-06-2004, 11:23 AM   #1
']['HeBroken
Member
 
Registered: Oct 2004
Posts: 35

Rep: Reputation: 15
Unix Shell Programming If Statement


ok i think i have the concept down on the programming language i just made a quick little proggie that will help me understand this a little better

Code:
print  -n "\n enter a b or c "
read char


      if (char = [aA] ) 
  char = you entered the letter A:
else
      if (char = [bB] )then
  char = you entered the letter B:
else
     if ( char =[cC] )
   char = you entered the letter C:
endif
now what am i doing wrong here? please help
 
Old 12-06-2004, 01:29 PM   #2
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
what you're doing wrong:

1) not posting what language you're attempting to use
2) useing malformed syntax -- your spaceing differs in your if constraints, and you only use one "then" statement... don't get me started on your use of "char" ...

edit:
(since you say this is for shell scripting, what shell -- bash?)
 
Old 12-06-2004, 04:21 PM   #3
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
To say the same thing a little more politely:

It depends on what script language you are using. For 'bash', for example (the default Linux shell), 'if' statements need to be surrounded in single or double square-brackets, and also require a semicolon and 'then' statement with each 'if' and 'elif'.

I'm not sure about the use of a regular expression on the right side of the comparison; you may need to use 'expr' for that.

But then again, this all depends on your choice of language, as scripting languages can be quite different in syntax.

Last edited by wapcaplet; 12-06-2004 at 04:23 PM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
UNIX shell programming Tozilla Programming 39 02-26-2009 08:29 AM
Problem with unix if statement abefroman Programming 3 07-30-2005 05:24 PM
unix systems programming in c saiz66 Programming 9 10-04-2004 11:04 AM
c programming in unix dilberim82 Programming 7 04-21-2004 05:32 PM
UNIX (Linux, BSD, etc) Programming :: UNIX kuphryn Programming 8 04-05-2004 12:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:11 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration