[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell Script (If and Else) problem



%% Joachim Fahnenmüller <jfahnenmueller@web.de> writes:

  jf> It should read:

  jf> if [ ... ];
  jf> 	then command;
  jf> 	else other_command;
  jf> fi

  jf> (mind the semicolons!)

Actually, you don't need ANY of those semicolons.

Bourne syntax is very regular, so it's pretty easy to know when you need
a semicolon and when you don't.  Put overly simply, semicolons replace
newlines.  In your example you have newlines so you don't need
semicolons.  All of these are equivalent in Bourne shell syntax (and
that includes sh, ksh, bash, and zsh):

    if [ ... ];
	then command;
	else other_command;
    fi

-----

    if [ ... ]
	then command
	else other_command
    fi

-----

    if [ ... ]; then
        command
    else
        other_command
    fi

-----

    if [ ... ]; then command
    else other_command; fi

-----

    if [ ... ]; then command; else other_command; fi

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@nortel.com>           HASMAT--HA Software Mthds & Tools
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
        These are my opinions--Nortel takes no responsibility for them.



Reply to: