【问题标题】:why is the error occuring when i am running the script.how can i fix it?为什么我运行脚本时会出现错误。我该如何解决?
【发布时间】:2019-10-15 09:20:44
【问题描述】:

这是基于 Linux 中 shell 脚本中的 while 循环编写的脚本。

我使用了一个变量,想增加它的值直到小于 10。脚本中可能出现什么问题?

为了发现我运行了脚本并且错误即将到来。

【问题讨论】:

  • 您好,欢迎来到 Stack Overflow。请阅读Why not upload images of code on SO when asking a question? 另外,请确保您提交您的代码和您收到的错误。
  • 请以后慢慢来,自己写代码和问题中的错误。
  • 看来expr 语句已经用单引号括起来了。它应该被反引号或$(expr...) 之类的声明。
  • 尝试使用 ((a++)) 代替
  • @sungtm 我尝试了你的反引号建议,结果成功了..cheers!

标签: linux shell while-loop scripting


【解决方案1】:

在第 6 行,尝试:

a=`expr $a + 1`

或

a=$(expr $a + 1)

不是这个

a='expr $a + 1'

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多