如何运用C-SHELL 的函数?
例如:
#!/bin/csh
hello ( )
{
echo " Hello there today's date is `date` "
}
echo " new going to the hello . "
hell
echo " back "
运行后出错提示是:Badly placed ( )'s.
请教大家如何运用C-SHELL 的函数?谢谢!
以下是引用HTJIAN在2005-4-25 15:14:01的发言:
例如:
#!/bin/csh
hello ( )
{
echo " Hello there today's date is `date` "
}
echo " new going to the hello . "
hell
echo " back "
运行后出错提示是:Badly placed ( )'s.
请教大家如何运用C-SHELL 的函数?谢谢!
c shell 与c,c++ 是不相同,你上面的写法好像是c语言的写法啊!c shell 没有函数的槪念,它是对代码进行逐行解释的。
下面是用c shell 写的一个计算并显示1与100之间的所有数之和的小程序
#!/bin/csh
##Display 1 to 100 sum#
alias MATH 'echo "scale=6;\!*" | bc'
set Sum = 0set i = 1
while ($i <= 100)
set Sum = `MATH $Sum + $i` @ i++end
echo "Display 1 to 100 Sum: $Sum"
下面是用c++写的:(可以与c shell 比教一下)
#include <iostream.h>class SumNumber{ int sum; public: void display() { sum=0; for (int i=1; i<=100; i++) { sum = sum + i; } cout << "Display 1 to 100 sum: " << sum; }};
int main(){ SumNumber obj; obj.display(); return 0;}
要自己定义函数,function name { command...}
我想请教下各位,在脚本里面那大于号怎么用不了,谢谢.
能不能麻烦你发一份答案到我邮箱,zoushan3@yahoo.com.cn