0

Say I have the following function defined in my .bashrc:

foo (){
    touch $1
    }

I want to call this function in a makefile like so:

%.png : %.tex
    bash -i -c foo $<

But this complains about a missing operand. (The error is "touch: missing file operand", so it is calling touch...). I've seen some solutions to similar issues, but they aren't applicable since I need the automatic variable $< (or rather, its value) to be passed as an argument to the shell script.

I know I could work around this problem (copy the function wholesale into the makefile, for example) but I'm curious to see how I could solve my problem within the makefile.

1 Answer 1

1

Your problem is probably because you don't have enough quoting. The shell -c option takes its script as a single argument.

Consider:

$ bash -c echo hi
<prints nothing>

Versus:

$ bash -c 'echo hi'
hi
Sign up to request clarification or add additional context in comments.

3 Comments

I can't quote the argument to bash, because I need make to interpret $<. But I see how that's part of the problem.
No you don't. Make doesn't care about quotes. Make doesn't even know how to interpret a shell script to handle quoting properly. Make always expands every $ in the recipe, unless it's escaped via $$ The only variables you have to worry about enclosing in quote are shell variables, not make variables; $< is a make variable. Try it. It will work.
Oh right sure, if I actually removed the other bug from my makefile it would work perfectly! (my testing script was touching the dependency file, not the required output, so it looked like nothing was happening. (it should be foo $@)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.