Search For or Replace Spaces


/ Published in: Makefile
Save to your folder(s)

Make (and GMake) ignore spaces in many constructs, making it difficult to use a single space as a search string or a replacement string, for example. This trick works around the problem by assigning the space to a variable named SPACE and using that instead. So given this makefile:

NOTHING:=
SPACE:=$(NOTHING) $(NOTHING)
NAME_WITH_UNDERSCORES:=$(subst $(SPACE),_,$(NAME))
print : ; @echo $(NAME_WITH_UNDERSCORES)

The command

gmake NAME="Professor Hubert Farnsworth"

would print

Professor_Hubert_Farnsworth


Copy this code and paste it in your HTML
  1. NOTHING:=
  2. SPACE:=$(NOTHING) $(NOTHING)

URL: http://braindumpery.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.