DamV
DamV

Reputation: 35

Strange segfault when using bash into Makefile

I need to read a file line by line in a Makefile. The following trigger a segfault :

all:
    @cat myFile.txt | while read -r line; do echo $$(line); done

Strangely the following works (print the content of the file) :

all:
    @cat myFile.txt | while read -r line; do echo $$line; done

Any idea of the cause of the problem ?

Upvotes: 0

Views: 85

Answers (1)

l0b0
l0b0

Reputation: 58848

Well, $(line) (that is, the code after being un-escaped by Make) isn't going to do what you expect. It is a command substitution which will execute the literal command line, which may or may not be a command on your system.

In general, anything which either needs escape characters or which would have been written as more than one line in a shell script should probably be in a shell script. You'll save yourself headaches that way.

Upvotes: 3

Related Questions