Execute Go function from Bash Script

Say I have a Go script, called script1, that has a function, function1, that does not take any inputs.

Can I call that function from a bash script?

Upvotes: 1

Views: 908

Answers (1)

VonC
VonC

Reputation: 1324278

While you can add a main() function which would call your function1(), allowing a go run a single go file, you also have an alternative:

  • mkouhei/gosh: interactive Golang shell, which provides an easy-to-use interactive execution environment and enable to omit the main function
  • nickwells/gosh: allows you to write lines of Go code and have them run for you in a framework that provides the main() func and any necessary boilerplate code for some common requirements. The resulting program can be preserved for subsequent editing.

Upvotes: 1

Related Questions