Proposal: accept go run -c 'program text here'

134 views
Skip to first unread message

Dan Kegel

unread,
Jul 5, 2026, 9:31:12 PM (2 days ago) Jul 5
to golang-nuts
Evidently AIs like Claude expect unix languages to accept input on the commandline, e.g.

go run -e -c 'package main; func main() { println("hello"); }'

This mistake happens very frequently.  Presumably it's hallucinating -e and -c because various other tools accept those as flags to indicate the input is on the commandline.

I asked Claude's opinion on this:

--- snip ---

 Before you run that command, I'm going to file a bug against go to make your life easier.  Which example feels more natural to you for running short go programs: 1)  go run -c 'package main; func main()         

{println("hello");}'  or   2) echo 'package main; func main() {println("hello");}' | go run -         

------- snip ----

It replied:

------- snip ----                                                                                                               

Option 1 (go run -c '...') is what I instinctively reach for — it matches python -c, bash -c, perl -e. Less pipeline plumbing for quick checks.

------- snip ----

Why not obey the principle of least surprise here, and do what feels natural to this (non-sentient) user?

- Dan

Ian Lance Taylor

unread,
Jul 5, 2026, 9:36:23 PM (2 days ago) Jul 5
to Dan Kegel, golang-nuts
I don't feel strongly one way or another about whether the go tool
should support passing in the source, but I note that the suggested
approach would make "go run -c" very different from "go test -c".

Ian

Dan Kegel

unread,
Jul 5, 2026, 10:29:09 PM (2 days ago) Jul 5
to Ian Lance Taylor, golang-nuts
How about -e ?  That's what perl and ruby use.
- Dan

Jackie Li

unread,
Jul 6, 2026, 4:23:22 AM (yesterday) Jul 6
to golang-nuts
I like this! currently quick testing locally have to start with a file. Also I think for AI agent to run quick script, this would be perfect

Rob Pike

unread,
Jul 6, 2026, 6:11:29 AM (yesterday) Jul 6
to Jackie Li, golang-nuts
Surely these AI tools are powerful enough that you can tell them how to run the command rather than changing the language's tools to cover their inadequacies.

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/0d4be2ed-14a6-4a44-b834-704caede5ef0n%40googlegroups.com.

Dan Kegel

unread,
Jul 6, 2026, 10:33:24 PM (11 hours ago) Jul 6
to Rob Pike, Jackie Li, golang-nuts
On Mon, Jul 6, 2026 at 3:10 AM Rob Pike <r...@golang.org> wrote:
Surely these AI tools are powerful enough that you can tell them how to run the command rather than changing the language's tools to cover their inadequacies.

I've observed people never bothering to do go build; they want to treat go like an interpreter.
And most popular interpreters offer a way to run code from the commandline.
Here's a little rosetta stone:

# Program coming from stdin

echo 'echo "Hello, World!"' | sh

echo 'echo "Hello, World!"' | pwsh

echo 'print("Hello, World!")' | python3

echo 'print "Hello, World!\n"' | perl

echo 'puts "Hello, World!"' | ruby

echo '<?php echo "Hello, World!\n"; ?>' | php

echo 'console.log("Hello, World!")' | node

echo 'print("Hello, World!")' | lua

#not supported in go


# Program coming from commandline option

sh -c 'echo "Hello, World!"'

pwsh -Command 'echo "Hello, World!"'

python3 -c 'print("Hello, World!")'

perl -e 'print "Hello, World!\n"'

ruby -e 'puts "Hello, World!"'

php -r 'echo "Hello, World!\n";'

node -e 'console.log("Hello, World!")'

lua -e 'print("Hello, World!")'

awk 'BEGIN{print "Hello, World!"}'

echo 'package main; func main() {println("Hello, world!")}' > hello.go; go run hello.go; rm hello.go


It does seem worth supporting, at least to me, as an idiom for quickly printing out constants or running really tiny programs.

- Dan

Sebastien Binet

unread,
3:12 AM (7 hours ago) 3:12 AM
to Dan Kegel, Rob Pike, Jackie Li, golang-nuts
another option is to contribute to mvm (even though, I personally won't
anymore as it does accept AI contributions):
https://github.com/mvm-sh/mvm

$> mvm run -e "fmt.Println(1+2)"
3

ie: if one wants interpreter-like features, better work with an
interpreter.

-s

PS: that said, I suppose one could perhaps consider 'go run' accepting
code from stdin.

Brian Candler

unread,
4:01 AM (6 hours ago) 4:01 AM
to golang-nuts
On Tuesday, 7 July 2026 at 03:33:24 UTC+1 Dan Kegel wrote:
Here's a little rosetta stone:
...

#not supported in go



To be fair, I'm not sure many other *compiled* languages do this either - perhaps the list should also include Rust, C, C++, Swift, Java ?

Stephen Illingworth

unread,
4:37 AM (5 hours ago) 4:37 AM
to golang-nuts
Just for fun, I wondered how easy it would be to create a bash script that facilitates using Go in this way.


Usage would be something like

   echo 'println("hello world"); fmt.Println("goodbye")' | GORUN

   echo 'println(math.Pi)' | GORUN

Or using actual newlines

   echo '
   println("hello world")
   println("goodbye")
   ' | GORUN


On Tuesday, 7 July 2026 at 03:33:24 UTC+1 Dan Kegel wrote:

Touring Tim

unread,
4:47 AM (5 hours ago) 4:47 AM
to Stephen Illingworth, golang-nuts
I've observed people never bothering to do go build.

I wonder who these people are and why they would be using GO in the first place?  Send to be a very complicated deployment to install GO on every deployment


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages