1

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:

#!/bin/sh
g++ -o ./test.out ./test.cpp
./test.out

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).

asked May 31, 2013 at 16:50
3
  • Replace ./ with absolute path! For Example: /home/MyName/test.cpp Commented May 31, 2013 at 17:02
  • You need to run this in the same directory. Commented May 31, 2013 at 17:03
  • what are the permissions on the script file? is the execute bit turned on? Commented May 31, 2013 at 18:21

1 Answer 1

2

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.

answered Jun 1, 2013 at 1:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.