Simple bash script; what's wrong with this syntax?

前端 未结 3 1474
后悔当初
后悔当初 2021-01-24 08:51

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 [\"$         


        
3条回答
  •  情书的邮戳
    2021-01-24 09:28

    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 ]).

    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.

    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.

提交回复
热议问题