0

I am new to shell script. I create the below script to count the total lines of files in directory.

It looks simple. line 7 is giving the correct number for the file.

#!/bin/bash
  
totalCount=0;
count=0;

for f in "$1"/*
do
  echo $(grep -o 'timestamp' "$f" | wc -l);        #line 7
  count = $(grep -o 'timestamp' "$f" | wc -l);     #line 8
  totalCount = totalCount + count;                 #line 9
done

echo $totalCount

however, line 8 and 9 keep giving below errors.

./myscript.sh: line 9: count: command not found
./myscript.sh: line 10: totalCount: command not found

I tried to change 'count' to '$count', still does not work.

What am i missing here?

yolenoyer
  • 8,797
  • 2
  • 27
  • 61
user1559625
  • 2,583
  • 5
  • 37
  • 75
  • 3
    Assignments shouldn't have spaces around the `=`. – choroba Apr 19 '21 at 12:10
  • Also, `totalCount=...` is missing a `$()` around the `...`. Try https://www.shellcheck.net/; it finds errors like these, explains them, and suggests fixes. – Socowi Apr 19 '21 at 12:12
  • Check https://www.shellcheck.net/ for common shell errors like the one mentioned above. – 0stone0 Apr 19 '21 at 12:12

0 Answers0