How can I execute a Swift script at a remote URL?

In the terminal, is there a way to run a script at https://website.com/script.swift?

In my limited understanding of curl, it will only accept an .sh extension. But essentially that's what I'm looking for.

I'm reasonably sure that there's nothing in the swift REPL that will handle a download of content, so I think you'd need to resort to a "bash pipe" kind of structure if you want to do this. I just double checked, and swift will accept swift content through STDIN, so it could be something like

curl -fsSL https://website.com/script.swift | swift

I haven't tried hosting any content myself to work out how to structure the specifics, but that's a gist that I think might work.

1 Like

Clever. Unfortunately, the REPL really didn't want to cooperate. The script itself also downloads some files.

As a workaround, I ended up writing a little helper script that downloads, runs and deletes my real setup script and now it works lol :sweat_smile:

#!/bin/sh

curl https://website.com/script.swift --output script.swift
chmod +x script.swift
swift script.swift
rm script.swift