Pergunta

How can I run a script inside cygwin after it launches?

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.

Also if there is a way to run scripts when closing like umount, rmdir and others.

Foi útil?

Solução

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_profile file, for example

source foo.sh
source bar.sh
source baz.sh

Bash man page

Outras dicas

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:

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.

Thought this might help someone..

.bash_login is what you actually need :P

I solved this issue by combining a few of the given answers.

In Cygwin

So first of all I ran which bash and changed to that directory.

Then I opened up the .bash_profile and tacked on the code I wanted to run at startup. (For me it was simply auto changing dir)

Then just save the changes, restart Cygwin and Boom! I was in my new dir :)

Hope this helps someone!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top