Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ogicse!schaefer From: schaefer@ogicse.ogi.edu (Barton E. Schaefer) Newsgroups: comp.unix.shell Subject: Re: Help needed with conditional statement for alias in csh Message-ID: <12211@ogicse.ogi.edu> Date: 18 Sep 90 16:47:47 GMT References: <6929.26ed0b53@uwovax.uwo.ca> <6932.26ed237f@uwovax.uwo.ca> Organization: Oregon Graduate Institute (formerly OGC), Beaverton, OR Lines: 69 In article <6929.26ed0b53@uwovax.uwo.ca> J G Miller writes: } } I have been having great problems in setting up an alias within csh. } } if ( { test -s /usr/spool/mail/miller } ) then; echo "" ; echo "New mail" ;\ } echo "" ; endif } } Could somebody please tell me what I am doing wrong and how to do } this in a one line command that can be aliased? In article <6932.26ed237f@uwovax.uwo.ca> he goes on: } In article <6929.26ed0b53@uwovax.uwo.ca>, miller@uwovax.uwo.ca (Greg Miller) writes: } } Further to my original post, I have since found that the problem is } not associated with the brackets around the expression but is } related to the execution of test. Chris Torek has already explained that it is csh brain-damage, not a problem with "the execution of test", that causes this. } And ideas on why this bizarre behavior and how to get it to } work properly? Don't use any "then", "else" or "endif". The csh "if" syntax also allows if condition simple-command where simple-command can't be a parenthesized subshell or control statement (while, foreach) of any kind, and can't contain separators e.g. `|' or `;' are out. First problem: You want three lines of output, but you can't use three echo commands. Solution (`%' is the csh prompt): __________ % setenv NEW_MAIL_MESSAGE '\ New mail\ ' % printenv NEW_MAIL_MESSAGE New mail % __________ So in the alias, you use: if { test -s /usr/spool/mail/miller } printenv NEW_MAIL_MESSAGE Note that the ( ) around the { } were redundant. In general, the way to put conditionals into csh aliases is to use a series of simple-if statements like the one above. Here's an example from my .cshrc. The backslashes are for readability in this posting only -- if you actually want to use this, you have to remove the backslash-newline-tab sequences and make the pp alias into one long line. Ah, the vagaries of csh .... # Default pushd to home directory (like cd) # if there is no top-of-stack to swap with. alias pp 'set pd=(\!*:q);\ if ($#pd == 0) set pd=(`dirs` ~);\ if ($#pd > 1) shift pd;\ pushd $pd[1] >& /dev/null;\ if ($#pd > 1) popd +2 >& /dev/null;\ unset pd;\ dirs' -- Bart Schaefer schaefer@cse.ogi.edu