[Makefile] Get Prefix or Suffix from String
Source code:
1 2 3 4 5 6 7 8 | STR=1.0.4-1ubuntu0.16.10.1 PREFIX=$(shell echo $(STR) | head -c 5) SUFFIX=$(shell echo $(STR) | tail -c 10) default: @echo "string: \033[92m$(STR)\033[0m" @echo "prefix: \033[92m$(PREFIX)\033[0m" @echo "suffix: \033[92m$(SUFFIX)\033[0m" |
shell command head/tail are used to get prefix/suffix from string.
Output:
string: 1.0.4-1ubuntu0.16.10.1
prefix: 1.0.4
suffix: 0.16.10.1
Tested on Ubuntu Linux 16.10, GNU make 4.1-9.
References:
[1] | [Makefile] Check Installed Package Version on Ubuntu Linux |
[2] |