Here is how to do it from the console.
- Type vi $GOBIN/go and press Enter. *
- Press the i key once to go into INSERT mode.
- Copy the two lines of code below and paste it into the new file.
- Once you are finished, press Escape.
- Type :wq and press Enter (yes, that is a colon).
- Type chmod 755 $GOBIN/go and press Enter.
* This assumes you have declared $GOBIN environment variable. See previous post if you have not.
Copy the two lines below and paste into new file:
#! /bin/bash
8g "$1" && 8l -o "${1/.go/.out}" "${1/.go/.8}" && rm -f "${1/.go/.8}" && echo "Output: ${1/.go/.out}"
8g "$1" && 8l -o "${1/.go/.out}" "${1/.go/.8}" && rm -f "${1/.go/.8}" && echo "Output: ${1/.go/.out}"
Note that I am using 8g and 8l commands because I am using a Mac. If you are using a different OS, then refer to this page and replace all the 8's with the appropriate number.
What It Does:
- Compiles the file.go source file into a file.8 object file.
- Links the file.8 object file and creates a file.out executable program.
- Deletes the file.8 object file.
- Outputs a confirmation message.
Usage and Output Demonstration:
jray$ lshello.go
jray$ go hello.go
Output: hello.out
jray$ ls
hello.go hello.out
jray$ ./hello.out
Hello World!
Note that the output file is named hello.out instead of the default 8.out.