xref: /freebsd/contrib/bmake/unit-tests/varname-dollar.mk (revision 148ee84570001f46b7b667c86573d378101c3801)
1# $NetBSD: varname-dollar.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
2#
3# Tests for the expression "$$", which looks as if it referred to a variable,
4# but simply expands to a single '$' sign.
5#
6# If there really were a special variable named '$', the expressions ${${DOLLAR}}
7# and $$ would always expand to the same value.
8
9# Using the dollar sign in variable names is tricky and not recommended.
10# To see that using this variable indeed affects the variable '$', run the
11# test individually with the -dv option.
12DOLLAR=		$$
13
14# At this point, the variable '$' is not defined. Therefore the second line
15# returns an empty string.
16# expect+1: dollar is $.
17.info dollar is $$.
18# expect+1: dollar in braces is .
19.info dollar in braces is ${${DOLLAR}}.
20
21# Now overwrite the '$' variable to see whether '$$' really expands to that
22# variable, or whether '$$' is handled by the parser.
23${DOLLAR}=	dollar
24
25# At this point, the variable '$' is defined, therefore its value is printed
26# in the second .info directive.
27# expect+1: dollar is $.
28.info dollar is $$.
29# expect+1: dollar in braces is dollar.
30.info dollar in braces is ${${DOLLAR}}.
31
32all:
33	@:;
34