Hi

In looking at some shell code that counts %’s in strings, I discovered this 
small discrepancy in OpenBSD’s shell. I’m not sure if this is a bug or expected 
behaviour so thought I would ask here. It seems to be the way set is used.

This shell script tickles the issue. The difference being the x is prefixed in 
the set command in the second case:

        msg="x%s konnte nicht genet werden, die Fehlermeldung lautet: %s."
        msg1="%s konnte nicht genet werden, die Fehlermeldung lautet: %s."

        IFS="%"

        set -- $msg
        echo "Message: $msg" >&2
        echo "$#" >&2

        set -- x$msg1
        echo "Message: $msg1"
        echo " with x before" >&2
        echo "$#" >&2

        echo "--------" >&2

On OpenBSD, this is the output:

Message: x%s konnte nicht genet werden, die Fehlermeldung lautet: %s.
3
Message: %s konnte nicht genet werden, die Fehlermeldung lautet: %s.
 with x before
4
————

On bash, NetBSD /bin/sh, MacOS /bin/sh and FreeBSD both values are 3. 

Any ideas? I can file a bug if necessary.
Kind regards
Chris




Reply via email to