0

I have a simple if loop which is working on one server but not on another. I could grep for the word in myscript.log log file.

#!/bin/ksh

./myscript.sh install $2 $3 $4
sleep 5
if grep -q SUCCESSFUL myscript.log
then
  echo "Install is good"
else
  echo "Error occured during Install"
fi

Output:

if: Expression Syntax.

Grep outside the script:

 mymachine:~>grep SUCCESSFUL myscript.log
 Install is SUCCESSFUL
8
  • Are the line endings in the file nonnative? Commented Oct 1, 2013 at 16:50
  • To narrow the problem, try replacing the grep expression with true and see if that works. Commented Oct 1, 2013 at 17:04
  • What does echo $SHELL say? Commented Oct 1, 2013 at 17:09
  • @devnull : echo $SHELL output is /usr/local/bin/tcsh Commented Oct 1, 2013 at 17:36
  • @rkyser : I replaced grep with true. Still I am getting same error if: Expression Syntax. Commented Oct 1, 2013 at 17:38

1 Answer 1

2

The error:

if: Expression Syntax

suggests that the shell you're using is not a variant of Bourne shell.

Another way to write the conditional statement would be:

grep -q SUCCESSFUL myscript.log && echo "Install is good" || echo "Error occured during Install"

(instead of the if ... fi loop.)

Sign up to request clarification or add additional context in comments.

1 Comment

for simplicity purpose I just gave echo statements..but I have some complex code inside..so the above code without if may not work for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.