7

In bash 4 (and above), to capitalize the first letter of a string stored in variable L1, I can do the following:

L1=en
Ll1=${L1^}
echo $Ll1

This prints En.

I'm trying to do something similar within a Makefile, but I can't get the ${L1^} syntax to work.

SHELL := /bin/bash

L1 = en
Ll1 := $(shell echo ${L1^})

all:
    @echo $(Ll1)

Produces blank output.

Can I get this to work with this kind of bash syntax without resorting to tr/sed?

P.S. I do need to assign it to a variable and not echo it directly. I'm using bash 4.3.48 and GNU make 4.1.

Proyag
  • 2,132
  • 13
  • 26

1 Answers1

9

You have two problems in your makefile, firstly the variable L1 is defined in make and isn't accessible in your call to your shell, use:

$(shell L1=$(L1); echo ...)

to define L1 in your shell.

The dollar sign needs to be escaped to not be interpreted by make:

$(shell L1=$(L1); echo $${L1^})
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123