Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 12-06-2004, 11:23 AM   #1
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

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

      if (char = [aA] ) 
  char = you entered the letter A:
      if (char = [bB] )then
  char = you entered the letter B:
     if ( char =[cC] )
   char = you entered the letter C:
now what am i doing wrong here? please help
Old 12-06-2004, 01:29 PM   #2
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" ...

(since you say this is for shell scripting, what shell -- bash?)
Old 12-06-2004, 04:21 PM   #3
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.


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 > Forums > Non-*NIX Forums > Programming

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

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