Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - String manipulation in Makefile

I've learned about string manipulation with bash, and more especially about substring replacement:

#! /bin/bash

VAR1="aaaa.bbbb.cccc"
VAR2="bbbb*"
echo ${VAR1%${VAR2}}

This bash script prints "aaaa.". I tried to include it in my makefile, but I can't make it work..

SHELL:=/bin/bash

VAR1="aaaa.bbbb.cccc"
VAR2="bbbb*"

all:
    @echo $${VAR1%$${VAR2}}

This Makefile only prints a blank line. I think I've misunderstood something, but can't figure out what. Any help would be really appreciated.

like image 616
Muja Avatar asked Jan 24 '26 21:01

Muja


1 Answers

No need to put double quotes around VAR1 and VAR2. And you need to use export if you want to put VAR1 and VAR2 above all:

SHELL:=/bin/bash

export VAR1=aaaa.bbbb.cccc
export VAR2=bbbb*

all:
    @echo $${VAR1%$${VAR2}}
like image 108
chifung7 Avatar answered Jan 26 '26 12:01

chifung7