Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the first letter of a make variable

Tags:

gnu-make

Is there a better way to get the first character of a GNU make variable than

FIRST=$(shell echo $(VARIABLE) | head -c 1)

(which is not only unwieldy but also calls the external shell)?

like image 210
Anaphory Avatar asked Oct 09 '12 11:10

Anaphory


People also ask

How do I get the first letter of a string?

The idea is to use charAt() method of String class to find the first and last character in a string. The charAt() method accepts a parameter as an index of the character to be returned. The first character in a string is present at index zero and the last character in a string is present at index length of string-1 .

How do I get the first letter of a word in PHP?

So you can easily use $i[0] to fetch first letter.

How do I get the first character in bash?

To access the first character of a string, we can use the (substring) parameter expansion syntax ${str:position:length} in the Bash shell. position: The starting position of a string extraction.

How do you get the first character of a string in TypeScript?

TypeScript - String charAt() charAt() is a method that returns the character from the specified index. Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string, called stringName, is stringName.


1 Answers

This is pretty horrible, but at least it doesn't invoke shell:

$(eval REMAINDER := $$$(VAR))          # variable minus the first char
FIRST := $(subst $(REMAINDER),,$(VAR)) # variable minus that
like image 180
Beta Avatar answered Oct 21 '22 04:10

Beta