LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Unix Shell Programming If Statement (https://www.linuxquestions.org/questions/programming-9/unix-shell-programming-if-statement-263249/)

']['HeBroken 12-06-2004 11:23 AM

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

secesh 12-06-2004 01:29 PM

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?)

wapcaplet 12-06-2004 04:21 PM

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.


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