Search code examples
windowsbashcygwin

Unable to execute bash script in windows cygwin


I am trying to execute bash script on windows using cygwin but getting error as commands not found

sample : test.sh

#!/bin/bash ls

and I am executing it as C:\Apps\cygwin64\bin\bash.exe /cygdrive/g/Scripts/test.sh

getting error as test.sh: line 2: ls: command not found


Solution

  • If you are running this from the Windows command prompt, or from a Windows batch file, in order for your PATH and other environment variables to be set correctly, you need to invoke the --login option. Run your command as follows:

     C:\Apps\cygwin64\bin\bash.exe --login -c "/cygdrive/g/Scripts/test.sh"
    

    This should do the trick.