Search code examples
cshshell

Syntax error in CShell Script


Write Script to read a positive integer number then it computes the following sequence: If the number is even, halve it If it is odd multiply it by 3 and add1

You should repeat this process until the value is 1, printing out each value and how many of these operations you performed.

#! bin\csh

echo "please enter any integer number :) "

set count=0

set number=$<

while($number != 1)

   if($number % 2) then

       @ number = number * 3 + 1 

   else

       @ number = number / 2

   endif

   echo " $number "

   @ count = count ++

end

echo I performed these operations $count times

When I run the script I get the following error: @: Expression Syntax.


Solution

  • I believe its $variable to obtain its value

    $
        Obtains the value of the variable. 
    
    @ var = $a + $x * $z
    

    source http://www.eng.hawaii.edu/Tutor/csh.html

    So that would be

    @count = $count +1 
    

    And the line

    #!bin\csh 
    

    makes me shiver