Cross-platform command line script (e.g. .bat and .sh)

后端 未结 2 490
臣服心动
臣服心动 2021-01-02 14:23

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

相关标签:
2条回答
  • 2021-01-02 14:27

    AFAIK, you can't directly run .sh files from Windows' cmd.exe. For that you'll need a *nix emulation layer to run the shell. Check out Cygwin or Msys/MinGW

    0 讨论(0)
  • 2021-01-02 14:52

    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.

    0 讨论(0)
提交回复
热议问题