grep "$linestart" $logFilePath/$logFileName if [ $? != 0 ] then
If this line is correctly copy/pasted then this is where the error is. This runs grep
on files named if
and [
, amongst others.
There needs to be a statement separator (semicolon or newline) between statements, such as before if
, and also before then
.
Explicitly examining $?
is a common antipattern; the succinct and idiomatic way to write this conditional is
if ! grep "$linestart" $logFilePath/$logFileName; then
...
As a matter of coding style, using cat
on a single file is useless; anything like cat file | grep regex
is better written as grep regex file
.
Also, error messages should properly be redirected to standard error (file descriptor 2):
echo "fail" >&2