script working periodically

We have a strange problem that started happening a few months ago. We have a unix script being called from within a microfocus cobol program using the call "SYSTEM" cobol command. The problem is sometimes the script will run, sometimes it wont - without us changing anything! The other strange thing is that we have multiple other cobol programs calling the same script but with a different passed parameter and those ALWAYS work!

The one that randomly fails is :

CALL "SYSTEM" using "$LAWDIR/interface/law_intf/lawson_xfer apcheck".

one of the ones that ALWAYS work is
CALL "SYSTEM" using "$LAWDIR/interface/law_intf/lawson_xfer achremit".

The script being called is lawson_xfer and the parameter is the interface name.
When it errors on us, it gives us the error:

sh: 0403-057 Syntax error at line 1 : `(' is not expected.
$LAWDIR/interface/law_intf/lawson_xfer apcheck

Again, sometimes (but rarely) it will run fine without the error and we dont change a thing. Any ideas on why this would happen, especially where it will work every once in a while?

Generally I would expect this to be due a variable that is not quoted properly. Without seeing your script, it is rather difficult to say exactly where it would come in.

Consider the following:

var=`/some/command`

if [ $var = yes ] ; then
    # do something
else
    # do something else
fi

If /some/command outputs "yes", or "no" then it will be have as you expect. However, if it outputs "(go ask bob)", I bet that the "if" statement would complain about the "(" before "go". For this example, the fix is rather simple:

var="`/some/command`"

if [ "$var" = yes ] ; then
    # do something
else
    # do something else
fi

Note the " (double-quote) characters around `/some/command` and $var.