Prev: In the Bible: the foreign women are prostitutes, crooked, evil, unfaithful, robbers etc
Next: Want to obtain single line output based on a file.
From: Maxwell Lol on 23 Jan 2010 08:14 Melvin <whereismelvin(a)gmail.com> writes: > Hi, > > I was trying to code a simple while loop in tcsh shell. > > #!/bin/tcsh > set cnt=5 > while ($cnt > 0) > cnt = $cnt(`expr($cnt - 1)) > end > > However I am getting the following error : > cnt=4: command not found (Error is going on till <ctrl+c> is pressed. > > Is this an error with the syntax? I suggest several improvements 1) invoke the shell with -f to prevent ~/.cshrc from interfering with the script. #!/bin/tcsh -f 2) add spaces around the parentheses to improve portability while ( $cnt > 0 ) 3) there are two ways to decrement cnt: @ cnt-- set cnt = `expr $cnt - 1`
From: Ed Morton on 23 Jan 2010 10:03
On 1/22/2010 12:48 AM, Melvin wrote: > Hi, > > I was trying to code a simple while loop in tcsh shell. > > #!/bin/tcsh > set cnt=5 > while ($cnt> 0) > cnt = $cnt(`expr($cnt - 1)) > end > > However I am getting the following error : > cnt=4: command not found (Error is going on till<ctrl+c> is pressed. > > Is this an error with the syntax? > > Thanks > Unix baby > In general, don't write loops in shell unless your moving files around or doing something with processes, and don't write shell scripts in [t]csh. Search the archives for why not. If you tell us what it is you're trying to do we can advise you on the right approach. If it was just to print the numbers 5 through 1 that would be: seq 5 -1 1 See - no loop. Regards, Ed. |