xref: /freebsd/contrib/bmake/unit-tests/varname-dollar.mk (revision 148ee84570001f46b7b667c86573d378101c3801)
1*148ee845SSimon J. Gerraty# $NetBSD: varname-dollar.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the expression "$$", which looks as if it referred to a variable,
42c3632d1SSimon J. Gerraty# but simply expands to a single '$' sign.
52c3632d1SSimon J. Gerraty#
62c3632d1SSimon J. Gerraty# If there really were a special variable named '$', the expressions ${${DOLLAR}}
72c3632d1SSimon J. Gerraty# and $$ would always expand to the same value.
82c3632d1SSimon J. Gerraty
92c3632d1SSimon J. Gerraty# Using the dollar sign in variable names is tricky and not recommended.
102c3632d1SSimon J. Gerraty# To see that using this variable indeed affects the variable '$', run the
112c3632d1SSimon J. Gerraty# test individually with the -dv option.
122c3632d1SSimon J. GerratyDOLLAR=		$$
132c3632d1SSimon J. Gerraty
142c3632d1SSimon J. Gerraty# At this point, the variable '$' is not defined. Therefore the second line
152c3632d1SSimon J. Gerraty# returns an empty string.
16*148ee845SSimon J. Gerraty# expect+1: dollar is $.
172c3632d1SSimon J. Gerraty.info dollar is $$.
18*148ee845SSimon J. Gerraty# expect+1: dollar in braces is .
192c3632d1SSimon J. Gerraty.info dollar in braces is ${${DOLLAR}}.
202c3632d1SSimon J. Gerraty
212c3632d1SSimon J. Gerraty# Now overwrite the '$' variable to see whether '$$' really expands to that
222c3632d1SSimon J. Gerraty# variable, or whether '$$' is handled by the parser.
232c3632d1SSimon J. Gerraty${DOLLAR}=	dollar
242c3632d1SSimon J. Gerraty
252c3632d1SSimon J. Gerraty# At this point, the variable '$' is defined, therefore its value is printed
262c3632d1SSimon J. Gerraty# in the second .info directive.
27*148ee845SSimon J. Gerraty# expect+1: dollar is $.
282c3632d1SSimon J. Gerraty.info dollar is $$.
29*148ee845SSimon J. Gerraty# expect+1: dollar in braces is dollar.
302c3632d1SSimon J. Gerraty.info dollar in braces is ${${DOLLAR}}.
312c3632d1SSimon J. Gerraty
322c3632d1SSimon J. Gerratyall:
332c3632d1SSimon J. Gerraty	@:;
34