I am newbie to Git bash.
Just out of curiosity trying to make a .bat file which contains commands(Dont know if Git Bash supports .bat file)
What I want to achieve is simply drag and drop this .bat file to Git Bash terminal
and commands in the file get executed(Is it possible?).
My commands in .bat file
export HOME2="C:\Program Files\directoy"
Git Bash can execute bash scripts, but not bat scripts. If you rename the file to
script.sh and rewrite like this, then Git Bash should be able to execute it:
#!/bin/bash cd 'C:\Users\USER\abc\xyz' cd 'C:\Users\USER\abc\xyz\pqr' export HOME='C:\Users\USER\some_directory' export HOME2='C:\Program Files\directoy'
I replaced the double quotes with single quotes. Otherwise the backslashes would be used as escape characters, for example Git Bash would try to execute
cd C:UsersUSERabcxyz. Actually it's better to write paths in Git Bash like this:
#!/bin/bash cd '/c/Users/USER/abc/xyz' cd '/c/Users/USER/abc/xyz/pqr' export HOME='/c/Users/USER/some_directory' export HOME2='/c/Program Files/directoy'
In any case, I think what you're looking for is NOT "executing", but "sourcing". If you source this script, the commands will be executed in your current shell. So
HOME2 will be set in your current shell. If you execute this, that will launch a new shell, which will execute the
cd commands and set
HOME2 but those settings won't affect your current shell.
It's possible to create
script.sh files and execute them by double clicking. But it is not possible to source them by double clicking, or to have them sourced by drag and drop to a Git Bash window.