Either there's something fishy with my Solaris 10 csh implementation of if statement or I don't get something right (of course the second is very well probable in my case at least) but when I do:

% if 1 then <enter>

=> nothing happends

And when I do:

% if 0 then

=> which is what I would expect also in the first case. Couse otherwise I have no way to finish constructing my statement without getting

if: improper then

And could I really kindly ask you not to start your appreciated answer with "Don't use csh"... You can end it with it, if you really feel like it. Couse in last several years up to now csh has served me quite well for my interactive purposes and for this little scripting that I do I use Bourne shell or bash.

Thank you


First, understand that (in csh) endif is a no-op (no operation) if there are no pending if(s) to close. Executing it has no effect.

% endif

So, if it is clear (because of a value of 1, which means true to csh, exactly as in c language) that the commands after the if will be executed, there is no need to delay their execution, and they are "allowed" to have an effect immediately:

% if (1) then
% echo yes
% echo no
% endif

However, for a false value (0), the execution is avoided until a endif is executed.

% if (0) then
? echo yes
? echo no
? endif

That is simply how the csh works.

Note: I do not get if: improper then with if 0 then. Maybe the error is somewhere else.


Well ... Some clarification may be in order. If I write (spaces before the <enter> added only for clarity, disregard them):

% if 0 then                            <enter> !!!!!!!!!!!!!
? echo Hello there
? echo Yes
? endif

I get no error.

If I write:

% if 0 then echo Hello there                       <enter> !!!!!!!!!!!!!
% if: Improper then.

I get your error.

  • Okay, makes sense. It is an interactive use afterall. I cannot expect that it'll behave like the in scripts i.e. that I have to write the whole statement up to endif.
    – stevica
    Sep 12 '18 at 7:19
  • You need to run if 0 then echo Hello there. which is how the questioner was "finish[ing] constructing my statement".
    – JdeBP
    Sep 12 '18 at 8:07
  • @JdeBP Well, if you mean that the whole command line (one line) is if 0 then echo Hello there then: yes, there is an error (a syntax error). But that is not what I meant :-), sorry. Please read more detail after the EDIT in the question.
    – IsaaC
    Sep 13 '18 at 1:41

The value 1 is equivalent to FALSE at shell level.

Also please keep in mind that csh is a bit fishy since theif is not a csh keyword, but rather a builtin command.

In csh, the if builtin calls a separate parser that reads until the statement was read completely.

Note that unlike on FreeBSD and maybe on Linux, csh on Solaris is not identical to tcsh but a different binary. But even tcsh behaves this way on Solaris.

In general, csh is inconsistent, see e.g. http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

  • Your information about Linux is wrong. On Debian Linux, just for starters, they are the TENEX C shell and the C shell, It is FreeBSD where they are the same program.
    – JdeBP
    Sep 11 '18 at 14:44
  • Well on FreeBSD, I am sure about them being identical.
    – schily
    Sep 11 '18 at 15:09
  • No, absolutely NO. In csh a value of 1 is equivalent to TRUE. Try if (1) echo yes. Please rt-fine-m.
    – IsaaC
    Sep 11 '18 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.