I just created a rickroll prank to play on friends and family. I want to be able to download the file from github using a curl command which works. My issue is that when I use a pipe and try to execute the script it does it right after curl gets executed and before it downloads the file.
This is the command I am trying to run:
curl -L -O https://raw.githubusercontent.com/krish-penumarty/RickRollPrank/master/rickroll.py | python rickroll.py
(curl -L -O https://raw.githubusercontent.com/krish-penumarty/RickRollPrank/master/rickroll.py; sleep 10) | python rickroll.py
Expanding on my comment.
There are several ways to chain commands using most shell languages (here I assume sh / bash dialect).
;will just run each command sequentially, starting the next one as the previous one completes.
;but aborts the chain as soon as a command returns an error (any non-0 return code).
&&but aborts the chain as soon as a command succeeds (returns 0).
What you tried to do here is neither of those, it's piping. Triggered by
|, it causes commands on its sides to be run at once, with the standard output of the left-hand one being fed into the standard input of the right-hand one.
Your second example doesn't work either, because it causes two sequences to be run in parallel:
curl, followed by a
sleeponce it finishes.
pythoncommand, run simultaneously with anything written by the first sequence redirected as its input.
So fix it:
command1 && command2, will run
curl, wait for it to complete, and only run
And again, you can use your example to show how harmful it can be to run commands one doesn't fully understand. Have your script write “All your files have been deleted” in red, it can be good for educating people on that subject.