a couple of things. what are the values of the $lgrep and $SAM_CMD?
and logic for most UNIX commands is that a return of 0 is good so a -ne (not equal) compare to 0 should have a error message of "Error".
Now what you need to watch is that the value of $? is from the last command run before the check.so if you have a string of commands then it may not be what is expected.
[CODE]
eval $lgrep $SAM_CMD ; if [ $? -eq 0 ] ; then echo "No Error" ; fi
change to
eval $lgrep $SAM_CMD ; rslt=$? ; if [ "$rslt." = "0." ]; then echo "No Error"; fi
The original error message came from the extra semi-colon after "then".
Please post all relevant parts of the script, or the whole script.
Please post the command and the lines which set the variables.
It think I get your logic but I can't think of a simple grep which would return exit status zero when it doesn't find something. Obviously "grep -v" is irrelevant in this context.
eval $lgrep $SAM_CMD ; if [ $? -ne 0 ] ; then echo "No Error" ; fi
Btw. If this is commercial code it is rarely ever necessary or desirable to use "eval".
In portable Shell scripts I have seen commands like echo executed as ECHO where ECHO is a function which decides which syntax to use.
. I'm not sure what you're doing with the first part but this code here reads "Test exit status to be not equal to 0 and if that evaluates to true, echo 'No Error'. I prefer the conditional test like above as opposed to if statements. Keeps code cleaner imho.
&& says do this code if the code to the left is true. || says do this if it fails or is not true. Good for one liners instead of worrying about if then syntax. Hope that helps a little for the future
If you could tell us what $lgrep and $SAM_CMD represent that would help so much. Give us an example of what those variable values are. That's what aix-guy means by expand the variables. With the test [ "$?" -ne 0 ] && echo "No Error" you don't need the IF. So
ED_Logs_Dir=/var/app/dir/slapd-ED/logs/acces #access has a typo
lgrep=/opt/ldap/lgrep
Access_OPS="\"ADD | MOD | DEL\""
Access_Err="\"err=0 | err=550 | err=20 | err=65\""
ED_CMD="$Access_OPS $ED_Logs_Dir/access | $lgrep -v $Access_Err" #the variable $ED_Logs_Dir already contains access so you don't need it here again
The reference to $ED_Logs_Dir in your last line expands to '/var/app/dir/slapd-ED/logs/acces/access' I'm sure that's unintended. So change your last line to
(Possibly controversial post, it's getting late here).
What is the problem with just putting the entire command into a shell script? To my mind all the variables and eval are not needed because there is no variation posted.
Please show examples, highlighting the command parameters which can change.
I would be surprised if the command itself is a variable. (Still trying to get rid of "eval").
Btw. Obfuscating the code does not make it easy for the next person.