m4 stops processing if new value contains hash (#)

207 views Asked by At

How to force m4 to continue processing line if value has hash?

$ echo a a a | m4 -D a=B+
B+ B+ B+
$ echo a a a | m4 -D a=B#
B# a a

I want identical behavior for second case - is it possible? (all three occurrences to be replaced).

In my understanding observed behavior is inconsistent and I couldn't find explanation in user manual.

1

There are 1 answers

5
uzsolt On BEST ANSWER

The # character is the first character of a comment and a newline is the last character. The m4 parses the first a and replace it to B#. It doesn't scan more because it runs into a comment.

The solution is to change the comment characters with changecom:

$ echo "changecom(BC,EC)a a a" | m4 -D a=B#
B# B# B#

Of course you can choose better comment begin- and end-sequences.

Ps. you can turn off the comment with simple changecom without arguments: echo changecom a a a. You can read it from manual :)