When you want a script, you typically want it in a single file. With usual setup using Swift Package Manager to interact with external libraries, you would end up a directory with Package.swift, which is bit much as a script.
By using swift-sh, you only have to take care of a single Swift file for your script, which makes your Swift script as portable as possible.
Script.swift
Script.swift is a small library that lets you write a Swift script with ease by using method chaining, inspired by bitfield/script.
Install
Via Swift Package Manager
Add this line in
dependencies
of yourPackage.swift
.Via
swift-sh
Add this line at the top of your Swift script. Refer to swift-sh documentation for more details.
Usage
exec
ifExists
write
read
countLines
concat
asArray
See documentation for more details.
Using
Script.swift
withswift-sh
When you want a script, you typically want it in a single file. With usual setup using Swift Package Manager to interact with external libraries, you would end up a directory with
Package.swift
, which is bit much as a script.By using
swift-sh
, you only have to take care of a single Swift file for your script, which makes your Swift script as portable as possible.Examples
echo.swift
Acknowledgements