0
votes

gnu make https://www.gnu.org/software/make/manual/make.html#toc-Functions-for-Transforming-Text has sort function. The description for the sort function states that sort function

Sorts the words of list in lexical order, removing duplicate words. The output is a list of words separated by single spaces.

I created a test makefile like this

TEST="this is a test test test test test"

all:

     @echo $(sort $(TEST))

My output is This is a test test

The duplicates were not entirely removed from the string! Am I interpreting the sort function incorrectly? Or is it a bug with gnu make?

1
Correction the TEST variable is "This is a test test test test"imendel
Watch the double quotes. "This is a test test test test" becomes "This is a test test" which the shell prints as This is a test test.Beta
...It is odd that sort doesn't sort within a quoted string, but does remove duplicates therein...Beta
Your TEST variable contains 5 different words: "this, is, a, test and test". And only the test word is duplicated.Renaud Pacalet
Agreed that test is duplicate. But there are 3 duplicates. If I would have a string "test test test test" and I would like to remove duplicates I would think that the result would be string "test", do you agree?imendel

1 Answers

1
votes

The double quotes are in no way special. So the TEST variable contains the words "This, is, a, test, test, test and test" which are then sorted with duplicate removed as "This, a, is, test and test" and thus the shell gets(1) echo "This a is test test", interprets the double quote as string markers and outputs This a is test test (and not This is a test test see the place of the a).


(1) A useful tip to debug make issue like this is to set the SHELL variable to /bin/echo so you can see what the shell gets. For instance you'd have had as a result -c echo "this a is test test" with the Makefile

TEST="this is a test test test test"
SHELL=/bin/echo
all:
    @echo $(sort $(TEST))