Reputation: 24771
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?
Upvotes: 1
Views: 80
Reputation: 4716
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.
Upvotes: 2
Reputation: 77175
Two issues:
Issue 1:
You need to have spaces in test
operator. Change the following line:
if ["$isframecount" -eq 0]
to
if [ "$isframecount" -eq 0 ]
Issue 2:
$isframecount = 1
There should be no $
sign before variable and no spaces in the assignment operator
Change it to isframecount=1
Upvotes: 2
Reputation: 362037
if [ "$isframecount" -eq 0 ]
Spaces are required on both sides of the square brackets.
isframecount=1
No dollar sign, no spaces around =
in an assignment statement.
Upvotes: 2