-   Programming (
-   -   Unix Shell Programming If Statement (

']['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


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

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" ...

(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.