Scripting Swift
How to use Swift as shell script language.
Swift not only allows you to write compiled applications with or without UI interaction, but also is able to be run as command line shell scripts.
Simply start a new Swift file by adding the usual #! …
front matter as the first line of your source code and add the path to the location of the swiftc
command — and you're set. Here is a practical example:
Save the file as — for example — hello_swift.swift
and make it executable by setting the corresponding flag:
You then can execute the Swift script by dotting it like so:
Last updated
Was this helpful?