如何转义 m4 宏定义名称中的 $?

How to escape $ in m4 macro definition's name?

我尝试了以下代码

define(`$TITLE', `my title')
This is my $TITLE.

但当我用 m4 调用它时,文本保持不变。

看来是$的问题。我应该逃避它吗?

编辑:

我发现

define(`$TITLE', `my title')
This is my indir(`$TITLE')

可行,但有更好的方法吗?

另外,这样的宏名称是referred,因为非标准,我在哪里可以找到这样的名称的列表?

GNU M4 1.4.18 manual, section 5.1 Defining a macro

As a GNU extension, the first argument to define does not have to be a simple word. It can be any text string, even the empty string. A macro with a non-standard name cannot be invoked in the normal way, as the name is not recognized. It can only be referenced by the builtins indir (see Indir) and defn (see Defn).

Here 标准。它写道:

Macro names shall consist of letters, digits, and underscores, where the first character is not a digit. Tokens not of this form shall not be treated as macros.

我认为使用 defn 会更好(而不是 indir),因为 POSIX 标准不包含 indirdefn 是) defn 必须在其他 m4 实现上工作(不仅是 GNU)。

如果您的变量以下划线(而不是美元符号)开头,我认为您的情况会更好:_TITLE。它是有效的宏名称,可能不会出现在您的文本中:)