メモです。C:\Go\bin にパスを通したいとして、以下のようにするとマシン全体の Path に追加できます。
- PowerShell を管理者権限で起動する
以下を文字通りに入力する
[Environment]::SetEnvironmentVariable("Path", $env:Path+";C:\Go\bin", "Machine")
コマンドプロンプトを別途開いて
go
を打ってみる
GUI が諸事情で使えない人はどうぞ。
メモです。C:\Go\bin にパスを通したいとして、以下のようにするとマシン全体の Path に追加できます。
以下を文字通りに入力する
[Environment]::SetEnvironmentVariable("Path", $env:Path+";C:\Go\bin", "Machine")
コマンドプロンプトを別途開いて go
を打ってみる
GUI が諸事情で使えない人はどうぞ。
/usr/local/bin にある #!/usr/bin/python3
をみつけたい、場面です。
こんな感じ。
find /usr/local/bin -type file | xargs awk '/python3/ {print FILENAME} {nextfile}'
1行目だけ検査したらさっさと nextfile
で次に移るので OK というわけ。
nextfile Stop processing the current input file. The next input record read comes from the next input file. FILENAME and ARGIND are updated, FNR is reset to 1, and processing starts over with the first pattern in the AWK program. If the end of the input data is reached, the END block(s), if any, are executed.
追記
FNR
(行番号)を if で判定して nextfile
することで、任意の行数を処理できます。
あと、grep といいつつ awk なタイトル詐欺ですみません。
Linux 限定ですが、binfmt_misc を使えば shell script や Python と同じように実行ビットを立てるだけで実行できるようになります。
以下のスクリプトを /usr/local/bin/gorun
とでもして保存
#!/bin/sh exec go run "$@"
Debian/Ubuntu なら update-binfmts
があるので以下を実行
sudo update-binfmts --install go /usr/local/bin/gorun --extension go
Go スクリプトに実行ビットを立てる
chmod a+x hello.go
hello.go
が直接実行できるようになる
$ ./hello.go Hello World!
小ネタで頻出と思いますけど。