Running a shell script through Cygwin on Windows

后端 未结 6 1934
有刺的猬
有刺的猬 2020-12-07 18:14

I have a bunch of shell scripts that used to run on a Linux machine. Now, we\'ve switched over to Windows, and I need to run these scripts there. I have Cygwin installed, bu

6条回答
  •  不知归路
    2020-12-07 19:12

    If you don't mind always including .sh on the script file name, then you can keep the same script for Cygwin and Unix (Macbook).

    To illustrate:
    1. Always include .sh to your script file name, e.g., test1.sh
    2. test1.sh looks like the following as an example:
    #!/bin/bash echo '$0 = ' $0 echo '$1 = ' $1 filepath=$1 3. On Windows with Cygwin, you type "test1.sh" to run
    4. On a Unix, you also type "test1.sh" to run


    Note: On Windows, you need to use the file explorer to do following once:
    1. Open the file explorer
    2. Right-click on a file with .sh extension, like test1.sh
    3. Open with... -> Select sh.exe
    After this, your Windows 10 remembers to execute all .sh files with sh.exe.

    Note: Using this method, you do not need to prepend your script file name with bash to run

提交回复
热议问题