Module exposing Unix command line tools as Swift 5 @dynamicCallable functions


Swift5 macOS

Module exposing Unix command line tools as Swift 5 @dynamicCallable functions

A few words of warning: This is intended as a demo. It should work just fine, but in the name of error handling and proper Swift beauty, you might want to approach forking processes differently 🤓 (BTW: PRs are welcome!)

Part of this blog post: @dynamicCallable: Unix Tools as Swift Functions.

Sample tool

The regular Swift Package Manager setup process:

mkdir ShellConsumerTest && cd ShellConsumerTest
swift package init --type executable

Sample main.swift:

import Shell


Sample Package.swift:

// swift-tools-version:5.0

import PackageDescription

let package = Package(
    name: "ShellConsumerTest",
    dependencies: [
        .package(url: "",
                 from: "0.1.0"),
    targets: [
        .target(name: "ShellConsumerTest", dependencies: [ "Shell" ]),

Remember to add the dependency in two places. WET is best!

swift run and swift test patch the $PATH to just /usr/bin. You may want to run the binary directly to make lookup work properly.

For this to work, you need to have Swift 5+ installed.



Brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.


  • Swift Tools 5.0.0
View More Packages from this Author


  • None
Last updated: Tue Sep 05 2023 08:47:38 GMT-0900 (Hawaii-Aleutian Daylight Time)