1

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?

3
  • Must you name it function1, instead of building a standard main function? Commented Apr 11, 2022 at 20:18
  • I have a main function, function1 is separate from it. Commented Apr 11, 2022 at 20:21
  • The normal way you do this in the Go world is to create a cmd/function1 subdirectory and put a separate main inside function1 Commented Apr 11, 2022 at 20:24

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.