ContextI've set up a site to post scripts to which I can then execute later using the following command:curl -so /tmp/script http://scripts.programster.org/scripts/1?output=raw && . /tmp/scriptThis example script outputs hello world to the terminal.As you can see, that's rather long and messy and risks overwriting a user's file if they just happen to have a file called /tmp/script. I used to just pipe to bash like so:curl -s http://scripts.programster.org/scripts/1?output=raw | bashHowever, I want the command to work with scripts written in other languages such as PHP (using #!/usr/bin/php at the top of the script), hence the change to the first command. QuestionIs there a way that I can execute an online script without having to save it to the local filesystem, whilst also not knowing what program to execute it in beforehand? Perhaps there is a way to treat a url like a file which would allow me to do something like:. http://scripts.programster.org/scripts/1?output=raw
Execute an online script gracefully
scripting
Aside of security matters, I hope you do realise the risks of running external scripts, this can be done by combination of wget and source (dot) command . <(wget -q -O- http://scripts.programster.org/scripts/1?output=raw)That means sourcing the script text into current shellwget -O- makes download ot STDOUT, -q makes it quiet (free from messages)<(any command) is process substituion that allows interpret the output as a fileP.S. curl - equivalent forwget -q -O- is  curl -s -o-UPDATEThe above examples will sitll  not make use of she-bang of the external script, but will run in the context of the calling shell. To make use of the she-bang line, one have to save the file, make executable, and only then run.You can use mktemp which will guarantee unuque names, then you'll have take care of removing temporary files. This can be combined in a wrapper that would take the external url as  paramterHere's a working sample code for that kind of wrapper#/bin/bashexturl=${1?No external url specified}tmpexe=$(mktemp)trap 'rm $tmpexe' EXITcurl -s $exturl  -o $tmpexechmod 0755 $tmpexe$tmpexe