简单的bash脚本;这种语法有什么问题? [英] Simple bash script; what's wrong with this syntax?

查看:61
本文介绍了简单的bash脚本;这种语法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读bash脚本教程,这似乎应该可以工作,但是我显然缺少了一些东西:

I'm reading bash script tutorials and this seems like it should work, but I clearly am missing something:

isframecount=0
framecount=0
while read p; do
  if ["$isframecount" -eq 0]
    then 
    echo $p
    $isframecount = 1
    else
    echo "frame count"
    echo $p
    $isframecount = 0
  fi
done < $filenam

当我尝试运行以上命令时,出现找不到命令错误"消息;有指针吗?

I get "command not found errors" when I try to run the above; any pointers?

推荐答案

当心哪些地方重要,哪些地方不重要.在这种情况下,if ["$isframecount" -eq 0]应该为if [ "$isframecount" -eq 0 ](请参见[之后和]之前的空格).

Watch out for spaces where they matters and where there should be not. In this case, if ["$isframecount" -eq 0] should be if [ "$isframecount" -eq 0 ] (see the spaces after [ and before ]).

这样做的原因是[实际上是程序的名称...自己查看...键入ls /bin/[ ...现在,如果没有空间,那么bash会寻找程序名为["0"或类似名称的东西,您的路径中肯定不存在

The reason for this is that [ is actually the name of a program... See by yourself... Type ls /bin/[... Now, if there is no space, then bash will look for a program named ["0" or something similar, which most certainly does not exist in your path.

然后,相反的情况...在变量分配中,=周围必须没有空格.所以$isframecount = 1应该是isframecount=1.请注意,我也删除了美元符号,这是要走的路.

Then, the opposite situation... There must be no space around the = in variable assignment. So $isframecount = 1 should be isframecount=1. Note that I also removed the dollar sign, that's the way to go.

这篇关于简单的bash脚本;这种语法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆