English 中文(简体)
Syntax error in CShell Script
原标题:
  • 时间:2009-12-28 20:55:45
  •  标签:
  • csh
  • shell

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.

#! bincsh

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.

最佳回答

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

#!bincsh 

makes me shiver

问题回答

i get correct solution :)

#! /bin/csh

echo "please enter any integer number :) "

set count=0

set inc=1

set number=$<

while($number != 1)

   if($number % 2) then

       @ number = $number * 3 + 1 

   else

       @ number = $number / 2

   endif

   @ count = $count + $inc

   echo " $number "


end

echo I performed these operations $count times




相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签