猿问

如何启动并运行 sh 格式化程序?

目标是为 bash 脚本( .sh文件)设置格式。所以我正在尝试使用.sh formatter。来自项目的 github 快速入门部分;我已经安装并拉入了shfmt 模块GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt,如下所示:但是在尝试调用shfmt 命令时。我收到 common command not found 错误。我如何实际使用shfmt 命令。我的假设是即插即用,即我不需要真正去摆弄PATHsENVs



陪伴而非守候
浏览 257回答 2
2回答

慕标5832272

该命令安装为$HOME/go/bin/shfmt(除非设置了 GOBIN,否则为$GOBIN/shfmt):$ go help installusage: go install [-i] [build flags] [packages]Install compiles and installs the packages named by the import paths.Executables are installed in the directory named by the GOBIN environmentvariable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATHenvironment variable is not set.

largeQ

go install正如彼得所说,安装是在命令的帮助下进行的。我想一步一步地在 Windows 7 机器上为我工作,因为我敢打赌,你们中的一些人对 Go 语言一无所知,甚至不想听到它:从 golang.org 安装 go 语言(我当然使用了 Windows 安装程序)下载.sh 格式化程序并将其解压缩到某处使用您最喜欢的终端导航到根目录 ..\sh-master(我使用GitBash,或者您可以使用每个 Windows 默认具有的 cmd.exe)运行命令go install和安装应该开始安装完成后,通过终端(GitBash 或 cmd)导航到 $HOME/go/bin(在 Windows 上默认位于 C:\Users\your_username\go\bin 下)从这里您可以像这样使用 shfmt 命令shfmt -l -w yourBashScript.sh瞧!现在您的 bash 脚本 yourBashScript.sh 已修改和格式化)
随时随地看视频慕课网APP

相关分类

Go
我要回答