using swift-install
cd swift-shell && swift install
using make
cd swift-shell && make
swift-shell (or swift shell)
example:
swift-shell <options> <filename> <arguments>
options:
-t, --testable:
run with debug configuration and allow @testable imports
-u, --update:
rebuild manually, without modifying the input
-c, --clean:
remove the build folder and binaries associated with the input
-r, --remove:
remove the input project from cache
-e, --enable <feature1,feature2>:
enable experimental features separated by a comma without spaces
notes:
only supports a single option name or combined flags
using combined flags -u and -c will remove the project from cache
create a symbolic link if you would like to use swift-sh or swift sh
cache: ~/library/developer/.swift.shell.cache
- There can only be one combined flag, because it would limit the ability to read input arguments
- Package imports with git support and environment variable expansion
- Options for debugging, clearing and updating from cache
- Ability to support experimental features with the
enable
option
Create a swift file with the following contents
#!/usr/bin/env swift-shell
// tip: `swift` can expand `swift shell` to be read as `swift-shell`
let str = "Hello, World!"
print(str) // hey, something just happened
Then allow the file to be executed or run swift-shell <filename>
chmod +x hello.swift
./hello.swift
Add URL dependency
import Shell // @git/acrlc/shell
// @git or @github expands to https://github.com/acrlc/shell
URL dependency with branch specified
import Shell // @git:main/acrlc/shell
// sets the branch to main, which is the default
Add path dependency
import AsyncAlgorithms // ~/path/to/apple/swift-async-algorithms
import Other // $main/path/to/other/package
import Package // ..