I'm trying to make a simple script that will compile test.cpp but I cannot get it to work. I'm running the script like this:

> bash make.sh

And getting the following error:

: No such file or directory
g++: no input files
make.sh: line 3: ./test.out: No such file or directory

Here is make.sh:

g++ -o ./test.out ./test.cpp

I've tried it without the " ./ " and it still doesn't work. I am running Cygwin on Windows 7 with all the proper packages installed (I can compile and run from the shell itself, just not from script).

  • Replace ./ with absolute path! For Example: /home/MyName/test.cpp – Sepahrad Salour May 31 '13 at 17:02
  • You need to run this in the same directory. – Daniel Beck May 31 '13 at 17:03
  • what are the permissions on the script file? is the execute bit turned on? – Frank Thomas May 31 '13 at 18:21

Did you create make.sh with Notepad?  If so, every line ends with a CR (carriage return) and a LF (line feed).  Cygwin and its Unix-like programs cannot handle that; Unix expects lines in text files to end with just a LF (which Unix calls a “new line” character).  Edit your file with a Cygwin editor (e.g., vi or vim) and fix it.  If you cannot do that, try adding “; #” to the end of each line; that should cause bash to treat the offending CRs as comments.

To expand on the above: if my theory is correct, the second line of make.sh looks like:

g++ -o ./test.out ./test.cppCR

plus the LF that’s supposed to be there (that bash excludes from consideration).  So, g++ is looking for a file whose name is “./test.cppCR”, which, of course, doesn’t exist.  So it says:

./test.cppCR: No such file or directory

But, because of what a carriage return is, this causes the : No such file or directory to overwrite the ./test.cpp, so : No such file or directory is all you see.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.