找不到Shell脚本错误

曼尼什·巴尔蒂

我有此代码,我无法指出错误。打印用户给定号码表的简单程序。

这是代码:

#a function to calculate the table
call()
{
#to check if it is in function
  echo "in function"
#read from user a no whose table is to print
  read num
#taking counter
  i=0
  echo "going in loop"

        while [ $i -lt 10 ]
   do
        echo "in loop"

#incrementing the counter
        i=$(( $i + 1 ))

#s= i + sa
        s=$(($i * $num))

##printing the value of num
         echo "\t$num * $i =$s"
    done
  return 0
}


     while [ 1 ]
do
     echo "in main "

#calling the function call()
     echo "caliing call"
call()

#asking user to continue or not
     echo "COntinue.. or not [0/1] "
    read ch

 if [ $ch -eq 0 ]
   then
       {}
   else
       exit

 fi
done

输出是这个

nik-pc@nik:~$ sh cd.sh

in main 

caliing call

12

nik-pc@nik:~$
血红素

在中bash,调用(引用)函数只是使用函数的名称,()而不要使用。

因此,请更改call()为仅call引用已定义的名为的函数call

注意,您仍然需要()在函数声明时间。

因此,例如,在声明时:

foobar () { .... ;}

在引用时:

foobar

shdash)中,引用call()将被静默忽略,而不会引发错误,并且外壳程序将继续前进到脚本的下一行。

另外,除非您确定,否则最好使用bash运行此类脚本来避免意外情况。


另外,您的代码中还有许多可以改进的地方,这超出了此问题的范围。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章