I want to print out a string variable in upper case. I'm trying to use the m4_toupper macro, but my variable seems to be ignored.
For example, given the following code:
foobar="linux-gnu"
echo "${foobar}"
echo m4_toupper("x${foobar}")
echo "${foobar}"
Results in the following output:
linux-gnu
X
linux-gnu
Since the x is capitalized, I suspect that the m4 macro is working correctly, but perhaps not receiving my variable string -- yet, the echo statements seem to work fine. Why is an empty string being returned?
Your macro isn't ignored, it just gets evaluated at a different time than you're expecting. The M4sugar macros are evaluated when
configureis created. You seem to want to have the toupper function applied whenconfigureis run. You can do it at creation time by something like:but this won't help if
foobaris set up at runtime. Then you'll have to resort to one of the runtime techniques suggested by Fredrik Pihl (or something similar).In any case,
m4_toupper("x${foobar}")is changed to"X${FOOBAR}"so that's why it's not appearing, since${FOOBAR}is not defined in the environment.