0Pricing
Swift Academy · Lesson

Swift scripts (swift shebang), command-line tools

Create runnable Swift scripts with a shebang , read CommandLine.arguments , print help, and exit with proper status codes.

Why Swift scripts?

Swift can act as a scripting language. Use a shebang to run files directly, parse CommandLine.arguments, and exit with status codes for automation.

Shebang basics

Add #!/usr/bin/env swift as the first line, make the file executable, then run it like any shell script.

// First line (shebang) when saved to a file:
// #!/usr/bin/env swift
// Then mark file executable: chmod +x tool.swift
// Run directly: ./tool.swift

print("Hello from a Swift script!")

All lessons in this course

  1. Swift scripts (swift shebang), command-line tools
  2. C/Obj-C interop at a glance (no iOS specifics)
  3. Packaging binaries with SPM
← Back to Swift Academy