Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalize first letter of string in Makefile using bash 4 syntax

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.

like image 949
Proyag Avatar asked May 01 '18 09:05

Proyag


1 Answers

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^})
like image 126
Andreas Louv Avatar answered Oct 24 '22 10:10

Andreas Louv