1

I am trying to download two files, A and B, using curl in a Makefile. The download of A has to be finished to download B.

When I am executing the following command in zsh, the order is respected (B is being downloaded after A):

curl -o ./A.html https://myserv.com/script.php?file=A && \
curl -o ./B.html https://myserv.com/script.php?file=B

But when I put the same command in my Makefile, B and A are being downloaded concurrently:

all:  
    curl -o ./A.html https://myserv.com/script.php?file=A && \
    curl -o ./B.html https://myserv.com/script.php?file=B

I don't understand why? Any idea?

7
  • 1
    Try wrapping the path and url in quotes. Commented Jun 12 at 13:13
  • Is it also a requirement that download A has to complete with a success status in order to proceed to download B? That's what your use of && implies, but that's not how you describe your requirements. If that's not a requirement then simply using two separate commands would be natural. Commented Jun 12 at 22:07
  • @RenaudPacalet my question was edited by marc_s. Thanks to him, the makefile is not syntactically correct anymore. Commented Jun 16 at 12:05
  • @JohnBollinger yes, I need the first download has to be completed successfully before the other one. My issue was because there was no quotes as suggested by the first comment Commented Jun 16 at 12:07
  • @tony_merguez Indeed that was an unfortunate edit. Still, with the && operator, and assuming the shell is POSIX, the two files shall download sequentially, not concurrently. From the POSIX standard: The control operator && denotes an AND list. The format shall be: command1 [ && command2] ... First command1 shall be executed. If its exit status is zero, command2 shall be executed, and so on, until a command has a non-zero exit status or there are no more commands left to execute. What shell executes the recipes? Could it be that it is not POSIX? Commented Jun 16 at 13:42

2 Answers 2

0

How did you confirm that they are working concurrently? In my tests it does not show the same behavior, (see below). Second command waits for the completion of the first.

all:
    (curl -o ./A.html https://myserv.com/script.php?file=A; sleep 10) && curl -o ./B.html https://myserv.com/script.php?file=B

Alternatively, you can use Makefile style, i.e., create separate targets for downloading these files and show the dependency explicitly. (You can even change the target names to the filenames, but depending on your use case, this can behave wrong.)

.PHONY: A
A:
    curl -o ./A.html https://myserv.com/script.php?file=A

.PHONY: B
B: A
     curl -o ./B.html https://myserv.com/script.php?file=B

all: B
Sign up to request clarification or add additional context in comments.

Comments

0

As stated by @0stone0 in the comments, quoting the path and the url solves the issue.

Comments

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.