3
#!/bin/sh
echo "Hello from sh"

When I run this program (hello.sh) I get a command not found error. I'm using cygwin on Windows and I looked at cy's FAQ. It said to change the permissions to 755. I already did that and still no luck. I get the same error with these other two programs.

#!/usr/bin/env python
print "Hello from python"

#!/usr/local/bin/perl
print "Hello from perl\n";

Any answers are appreciated. Thanks.

4
  • I think that bash.exe does not have the PATH set up Commented Dec 8, 2013 at 1:21
  • How do I solve that issue? Commented Dec 8, 2013 at 1:26
  • possible duplicate of How do I run bash shell scripts in cygwin? Commented Aug 24, 2014 at 18:49
  • Duplicate (more recent but that has a better answer): stackoverflow.com/questions/25467390/… Commented Aug 24, 2014 at 18:50

3 Answers 3

4

As has already been said, you need to add the Cygwin binaries to your path. To do so, right click on "My Computer", click "Properties", then "Advanced", then "Environment Variables".

Create a new environment variable with name CYGWIN_HOME and value C:\cygwin (or wherever you installed cygwin. The default location is C:\cygwin\ so this should probably work for you).

Then edit the environment variable named "PATH", and tack on the following to the end:

;%CYGWIN_HOME%\bin;%CYGWIN_HOME%\sbin;%CYGWIN_HOME%\usr\bin;%CYGWIN_HOME%\usr\sbin;%CYGWIN_HOME%\usr\local\bin;%CYGWIN_HOME%\usr\local\sbin

Close your command prompt, then reopen it. The cygwin binaries should now be available. You can double-check this by typing "which bash". It should report the location of your bash executable

Sign up to request clarification or add additional context in comments.

Comments

0

I was getting the "command not found" error on a Perl script. That script has the shebang line: "#!/usr/bin/env perl" as the first line and my user is the owner who has execute permissions. I was trying to run the script using the command line "ppminstall.pl ?" (the script is set up to display documentation for using the script if passed the '?' argument). I was cd'd to the directory containing the script. The solution turned out to be to run it using "./ppminstall.pl ?", i.e. explicitly specify the current directory. I think that you might be able to add "." to the current path and get the original command line to work, but it does seem safer to me to use "./" to run it since it's pretty explicit about where the script that you want to run is located. It may be possible for someone to manipulate your Path variable and cause you to be running a version of the script that you didn't intend. The '.' and '/' characters are easy to type without taking your eyes off the screen, so it seems like a useful habit to get into. Of course, I don't know if that is your problem, but it was mine.

Comments

0

Maybe caused by the wrong line break?

Open this shell in Notepad++, and then check if the line break is UNIX(LF) in the lower right corner. If not, click the text Windows (CR LF) and then click Convert to UNIX(LF).

This works for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.