Short answer:
The easiest way is to install git for windows (git bash) and use shebang lines.
#!/usr/bin/env python||anyothercommand
Its the first thing I install on any computer because who doesn't want bash and we all use git right?
More info:
Unlike Cygwin, git bash uses your native windows applications and lets you use bash scripts without any configuration.
It will automatically treat any file with a shebang line as executable and run the command if its in your path same way bash will on Linux. It also just uses windows ENV variables so anything you add to your path to work from Powershell or cmd will work for git bash too.
You can edit env vars in windows by hitting start and typing env
should be the first option. Just edit your user path var (or global one for all users) and add any applications you want available in the command line.
Also installs git and hooks it up with windows credentials manager for you and makes it super easy to sign into 2fa enabled svn services like GitHub to bitbucket so you don't have to generate tokens.
Also comes with right-click menu to open bash in any location or even a GUI for just using git.
During install, I recommend you tell it to checkout as-is and commit as Unix line endings to be nice to your Linux and macOS buddies. I also recommend many other git configurations but that's another topic.
Another option:
Install WSL(1 not 2) which is even better but requires some configuration. (changing default drive mount paths hooking up credential manager manually etc can ask me about all that if you want there is a lot of tweaks I recommend for running Linux in windows.)
Using WSL altho more fiddly means you can have Linux versions of all your command line applications separate from your windows ones.
It can still run native windows exe files too if you want but Linux binaries will take precedence if installed.
To setup WSL run this command as admin in power shell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
*requires reboot
And then search Microsoft app store for Linux and pick a distro.
(I recommend Ubuntu 18LTS)
PS - you can also run WSL inside git bash 😏 oh and if you happen to use PHP, windows composer.exe will also use shebang lines to run WSL.
py
command for it to have any effect. - martineau