Native shebang: Difference between revisions
Content added Content deleted
(REXX) |
(Added Go) |
||
Line 545: | Line 545: | ||
</pre> |
</pre> |
||
=={{header|Go}}== |
|||
In Go, single line comments can only begin with // and so we have to use the former in place of a normal shebang (#!) to achieve the same effect. |
|||
The 'go run' command compiles a .go source code file to a binary executable and then runs the latter automatically. The executable is placed in a temporary directory which is then deleted when the process ends. |
|||
To cache the executable in the current directory, one would have to use 'go build' instead (replace the opening line with ///usr/bin/env go build echo.go; ./echo "$@"; exit). |
|||
The following works fine on Ubuntu 16.04. |
|||
<lang go>///usr/bin/env go run echo.go "$@"; exit |
|||
package main |
|||
import ( |
|||
"fmt" |
|||
"os" |
|||
) |
|||
func main() { |
|||
if len(os.Args) > 1 { |
|||
fmt.Println(os.Args[1]) |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
$ ./echo.go "Hello, world!" |
|||
Hello, world! |
|||
</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |