scripting-with-go

Execute Go scripts directly as standalone programs with go run.

Updated Jan 16, 2026
One-click install
npx skills add https://github.com/jeninh/ampskills-dotfile --skill scripting-with-go
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: scripting-with-go
Source: https://github.com/jeninh/ampskills-dotfile/tree/main/.agents/skills/scripting-with-go
Command: npx skills add https://github.com/jeninh/ampskills-dotfile --skill scripting-with-go

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enables Go scripts to execute directly as standalone programs without requiring a traditional shebang, simplifying script execution and portability.

Core Features & Use Cases

  • Executable Go scripts that run with a shell trick, allowing ./script.go to execute with full argument support.
  • Cross-environment compatibility by using go run via an initial directive, enabling quick automation in Go-enabled environments.
  • Use Case: When you want lightweight, shareable Go-based automation scripts that you can run without explicit compilation steps.

Quick Start

Create a new file named script.go with a first line that points to the Go runner, make it executable, and run it with arguments.

  • Example first line: //usr/bin/env go run "$0" "$@"; exit
  • After adding a minimal Go program, run: chmod +x script.go; ./script.go World

Frequently Asked Questions about scripting-with-go

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run a Go script directly as an executable file?

To run a Go script directly as an executable, add the shell directive //usr/bin/env go run "$0" "$@"; exit as the first line, make the file executable with chmod +x, and execute it using ./script.go. This invokes the Go toolchain automatically without explicit compilation.

Can I execute Go scripts without using a traditional shebang?

Yes, you can execute Go scripts without a traditional shebang by using a shell-wrapped first line. This directive tricks the shell into invoking go run, allowing the file to act as a standalone executable while maintaining full argument support.

What is the best way to create portable Go automation scripts?

The best way to create portable Go automation scripts is using a shell trick that invokes go run via an initial directive. This enables cross-environment compatibility for quick automation, testing, and prototypes without requiring manual compilation steps.

Do I need a Go toolchain installed to run executable Go scripts?

Yes, you need a Go toolchain available in your PATH to run executable Go scripts. The shell directive relies on go run to compile and execute the underlying Go code dynamically each time the script is invoked.

How do I pass command line arguments to a Go script executed with go run?

To pass command line arguments to a Go script, use the shell directive //usr/bin/env go run "$0" "$@"; exit. The "$@" component forwards all provided arguments directly to the Go program during execution.

Why does my executable Go script fail to run after adding the shell directive?

An executable Go script fails to run if file permissions are incorrect or the Go toolchain is missing from PATH. Ensure you run chmod +x on the file and verify your environment has Go installed properly.