Windows 上的 Git Bash - 在哪里存储以及如何调用 Bash 脚本
在 Windows 上使用 Git Bash,如果我创建一个 bash 脚本,我应该把它放在哪里以便我可以从 bash shell 访问它?
基本上,我想创建一个 bash shell 脚本来对文件等执行一些操作。
我想使用一些参数从 bash shell 内部调用该函数。然后脚本将完成其工作。
我对这个环境完全陌生。所以,我对bash的了解非常有限。
Using Git Bash on Windows, if I create a bash script, where do I put it so that I can access it from the bash shell?
Basically, I want to create a bash shell script that does some stuff with files etc.
I want to invoke the function from inside the bash shell with some parameters. The script will then do its work.
I am completely new to this environment. So, my knowledge of bash is very limited.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,您可以把它放在任何您想要的地方。但为了方便使用,您可能希望将其放在您的主目录中。要找到它,请打开 Git Bash 并输入以下内容:
它应该返回类似
/c/Documents and Settings/username
(或/c/Users/username
)的内容。在 Windows 术语中,如您所料,它位于“C:\Documents and Settings\username”。Well, you can put it anywhere you want. But for ease of use, you might want to put it in your home directory. To find it, open up Git Bash and type the following:
It should return something like
/c/Documents and Settings/username
(or/c/Users/username
). In Windows terminology, that it at "C:\Documents and Settings\username" as you would expect.您可以在多个位置放置自动加载的脚本。您可以执行此命令来查看系统上正在加载的位置以及加载顺序:
将脚本放置在其中一个位置(如果尚不存在则创建它),它将是可执行的。您还可以修改
.bashrc
中的$PATH
变量来添加自定义位置。值得注意的是,某些路径(例如
/bin
或/usr/bin
)通常包含系统关键程序,当其中的某些脚本被破坏时,您可能不会完全能够开始。通常首选路径为您的用户的/c/Users/username
或所有用户的/usr/local/bin
。There are several places you can put your scripts from which they are auto-loaded. You can execute this command to see which location are being loaded on your system, and in which order:
Place a script in one of the locations (or create it if it doesn't exist yet) and it will be executable. You can also modify the
$PATH
variable in your.bashrc
to add a custom location.It's important to note though that some of the paths, like
/bin
or/usr/bin
usually contain system-critical programs and when some script is broken in there you might not be able to start at all. Paths like/c/Users/username
for your user specifically, or/usr/local/bin
for all users, are usually preferred.你可以把它放在
/bin
中,它相当于C:\Program Files\Git\bin
(或类似的,取决于你安装 git 的位置)。You can put it in
/bin
which is equivalent toC:\Program Files\Git\bin
(or similar, depending on where you installed git).