質問

Can anyone explain what does the characters between -d and < $< does in the following makefile command?

tr -d "\`~@#$%^&*=+<>{}[]|/'" < $< | ./$(ANSWER) $(STOPWORDS) | sort > $@ 

Here STOPWORDS is a file with words and ANSWER is a executable.

役に立ちましたか?

解決 2

tr translates or deletes characters.

Passing -d tells tr it's going to delete the SET1 of characters it's provided

"`~@#$%^&*=+<>{}[]|/'" is the set of characters to be deleted.

< is a shell redirection character

$< is a one of the automatic make variables which identifies the name of the first prerequisite

So you're deleting all characters from that specific set that are found in the first prerequisite in the given make rule.

Here's a simple example -

Makefile:

all:text.txt
tr -d "\`~@#$%^&*=+<>{}[]|/'" < $<

Now given this text.txt file:

$ cat text.txt
huio7&*(njkvlsan7u#%$&*(FHhnjkl

run the make file and you'll see:

$ make
tr -d "\`~@#^&*=+<>{}[]|/'" < text.txt
huio7(njkvlsan7u%$(FHhnjkl

The &, *, and # are all missing now.

The vertical bar | is a pipe character which will take the output from this first command and send it to the next.


You asked why the $ and % weren't removed, the answer is because there are some characters that Make treats special. Take a look at the actual output of the command:

$ make
tr -d "\`~@#^&*=+<>{}[]|/'" < text.txt

The line that make actually executed did not include the $ and the % because make recognized special characters that didn't have escape characters (backslash) with them. Example, let's escape the %:

New Makefile:

all:text.txt
tr -d "\`~@#$\%^&*=+<>{}[]|/'" < $<

Now running this command we see:

$ make
tr -d "\`~@#\%^&*=+<>{}[]|/'" < stupid_text.txt
huio7(njkvlsan7u$(FHhnjkl

See how the % showed up in the make output and the string now has removed the %?

他のヒント

The tr command deletes (-d) all the listed characters ("\`~@#$%^&*=+<>{}[]|/'" except for the double quotes) from the file designated by $<. The output goes to the answer/stopwords command, and that output is sorted into an output file.

It actually has almost nothing to do with make except that $< and $@ are make variables.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top