I noticed that Windows 7 enables to execute .sh files as if they were .bat files. That got me wondering whether it is possible to write a .sh file such that it can be execut
You could use this:
rem(){ :;};rem ' @goto b ';echo sh;exit :b @echo batch
It's valid shell script and batch, and will execute different blocks depending on how it's run.
Modify the echo and @echo lines to do what you want.
echo
@echo