bash Cygwin 启动脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15325137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cygwin startup script
提问by codiac
How can I run a script inside cygwin after it launches?
启动后如何在 cygwin 中运行脚本?
I want to automatically add some mounts and run other scripts inside cygwin whenever it starts. I see that in linux it is as simply as adding a shell file inside etc/init.d However, i tried adding this dir and chmod +x add a shell, chmod that shell file, but does not work.
我想在 cygwin 启动时自动添加一些挂载并在其中运行其他脚本。我看到在linux中它就像在etc/init.d中添加一个shell文件一样简单但是,我尝试添加这个目录和chmod +x添加一个shell,chmod那个shell文件,但不起作用。
Also if there is a way to run scripts when closing like umount, rmdir and others.
此外,如果有一种方法可以在关闭时运行脚本,例如 umount、rmdir 等。
回答by Steven Penny
What you are looking for is
你要找的是
~/.bash_profile
AKA
又名
C:\cygwin\home\CPJ\.bash_profile
With a stock install this file is read on Cygwin startup. If you would like to add more files you can edit the .bash_profilefile, for example
使用库存安装,在 Cygwin 启动时读取此文件。如果您想添加更多文件,您可以编辑该.bash_profile文件,例如
source foo.sh
source bar.sh
source baz.sh
回答by Ruslan Abuzant
I am sorry to add to this very old question, but I think the accepted answer above has a glitch.
我很抱歉补充这个非常古老的问题,但我认为上面接受的答案有一个小故障。
Try to add a command to your .bash_profile as follows which I use for example to open a local SSH port:
尝试将命令添加到您的 .bash_profile 中,如下所示,我使用它来打开本地 SSH 端口:
ssh -D1080 root@localhost -g localhost
When you login interactively, another SSH session starts, which starts another, and another, and you're in an endless loop.
当您以交互方式登录时,将启动另一个 SSH 会话,然后又开始一个又一个,您将陷入无限循环。
Thought this might help someone..
认为这可能会帮助某人..
.bash_loginis what you actually need :P
.bash_login是你真正需要的:P
回答by Nathaniel Rogers
I solved this issue by combining a few of the given answers.
我通过结合几个给定的答案解决了这个问题。
In Cygwin
So first of all I ran which bashand changed to that directory.
所以首先我运行which bash并更改到该目录。
Then I opened up the .bash_profileand tacked on the code I wanted to run at startup. (For me it was simply auto changing dir)
然后我打开并添加了.bash_profile我想在启动时运行的代码。(对我来说,这只是自动更改目录)
Then just save the changes, restart Cygwin and Boom! I was in my new dir :)
然后只需保存更改,重新启动 Cygwin 和 Boom!我在我的新目录中 :)
Hope this helps someone!
希望这对某人有帮助!

