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 executed in Windows and Linux (let's say bash).
The first thing that comes to my mind is to fabricate an if-statement such that Windows and Ubuntu can deal with it and jump into the according block to execute plattform-specific commands. How could this be done?
Note: I know this is not good practice. I also know that scripting languages like Python are far better suited to solve this problem than a mixed-syntax command line script would be. I'm just curious...
bat) The command line utilities that control the Launcher (launcher.sh on UNIX operating systems and launcher. bat on Windows operating systems) can be configured specifically for running systems in multiple Launcher processes.
bat file is a windows batch file it contains a sequence of windows/dos commands. These cannot be used in a Unix shell prompt. A . sh file is a unix shell script it contains a series of unix commands.
Type 'sh' in cmd window to redirect into Bourne shell and run your commands in terminal. Git Bash comes with Git for Windows.
the scripts can be executed cross platform and be executed easily. easy to setup.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With