[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to achieve conversion to uppercase
From: |
Paul Smith |
Subject: |
Re: how to achieve conversion to uppercase |
Date: |
Tue, 10 Sep 2013 08:09:14 -0400 |
On Tue, 2013-09-10 at 10:09 +0100, Matej Kosik wrote:
> I am trying to figure out how to convert words to upper case.
>
> Make itself does not seem to have dedicated function for this
> particular task, unless I am mistaken, so I guess I had to rely on
> bash.
> In bash, something like this:
> var=foo; echo ${var^}
> works fine. I get:
> Foo
>
> However, if I try to embed this command with my makefile like this:
> $(shell var=foo; echo $${var^})
> then I get:
> /bin/sh: 1: Bad substitution
That's because make does not invoke bash. Make invokes /bin/sh, which
is a POSIX compliant shell, so it doesn't understand many of the special
bash extensions (note that even if /bin/sh is actually bash, when
invoked as /bin/sh it disables many of bash's extended features).
It's best not to rely on this anyway, as it's not portable at all.
> I am not sure what exactly that string expands to by make before it is
> passed to bash so I am not sure which escape characters are missing
> (if that is the problem).
It is not the problem. Try this from the command line:
/bin/sh -c 'var=foo; echo ${var^}'
To write this portably you can use the tr(1) program:
$(shell echo foo | tr a-z A-Z)
Or if you want to do it with make built-ins you can look at the GMSL:
http://gmsl.sourceforge.net/