-bash: ./p4: /bin/ksh^M: bad interpreter: No such file or directory

I keep getting this error and I am not sure why.

-bash: ./p4: /bin/ksh^M: bad interpreter: No such file or directory

First I run my makefile and this works fine:

goodmain: main.o
    gcc -o goodmain main.o

main.o: main.c
    gcc -c main.c

Then I want to limit my output so I created this shellscript.

#!/bin/ksh
goodmain $1 | sed -e '1,/mmxxaa/d'

I run it like this:

./p4 textfile

I thought $1 meant the second input. This works fine when I run it from the command line. Can anyone spot my issue?

Try:

cp p4 _p4 && tr -d '\r' < _p4 > p4 && rm _p4

Yes that fixed one problem. Now it can't seem to find my files.

$ ls -l
total 1364
-rwxr-xr-x. 1 n00930622 student  94563 Apr 23 23:55 a.out
-rwxrwxrwx. 1 n00930622 student     19 Apr 28 17:13 boo
-rw-r--r--. 1 n00930622 student     89 Apr 24 00:58 cookies
-rw-r--r--. 1 n00930622 student   1622 Dec  6 23:49 doc
-rw-r--r--. 1 n00930622 student    148 Apr 23 16:14 textfile
-rw-r--r--. 1 n00930622 student 597061 Apr 23 23:56 fn
-rwxr-xr-x. 1 n00930622 student  94563 Apr 28 16:56 goodmain
-rw-r--r--. 1 n00930622 student 427993 Apr 23 23:47 main.c
-rw-r--r--. 1 n00930622 student 145256 Apr 24 00:40 main.o
-rw-r--r--. 1 n00930622 student     72 Apr 28 16:53 makefile
-rwxrwxrwx. 1 n00930622 student     46 Apr 28 17:24 p4
$ ./p4 textfile
./p4: line 2: goodmain: not found

What do you get as output from the command:

ls *o*|od -bc

I assume that by now you're aware that when writing shell scripts you MUST use an editor that uses a single <newline> character as the line terminator on the output it produces (NOT the DOS <carriage-return><newline> character pair).

Yes I know, but no I did not remember. I thought I had my notepad++ set for unix files but it didn't work for some reason.

$ ls *o*|od -bc
0000000 141 056 157 165 164 012 142 157 157 012 143 157 157 153 151 145
          a   .   o   u   t  \n   b   o   o  \n   c   o   o   k   i   e
0000020 163 012 144 157 143 012 147 157 157 144 155 141 151 156 012 155
          s  \n   d   o   c  \n   g   o   o   d   m   a   i   n  \n   m
0000040 141 151 156 056 157 012
          a   i   n   .   o  \n
0000046

What PATH do you use?
You need to set the path to goodmain in your script, like /path/to/goodmain or by including it in the PATH variable.

Thank you thats it :). How would I add it to my PATH?

$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/22/n00930622/bin

In your script:

export PATH=$PATH:/path/to

or specify the PATH variable absolutely, without a reference to $PATH .

I use ksh as my login shell. The way I set PATH in my .profile file is:

PATH=$HOME/bin:$PATH:.
export PATH

which looks for commands in the bin subdirectory of my home directory first, the default locations set up by the system administrator on my system, and the current directory. I don' t include the current directory (specified by . ) when I'm running as root, and many people never put . in PATH to avoid security issues that can pop up if you execute commands in a directory where other people can create files. If you put . in path anywhere but as the last entry, it makes this more likely to be a problem.

If you are using bash as your login shell, you need to set PATH in the first file in your home directory that has a name in this list: .bash_profile , .bash_login , and .profile . After updating the way you initialize PATH you will need to either log out and log back in or run the command:

. filename

where filename is the name of the file in which you changed the way you set PATH .

I think, in this case this can be done simpler using

dos2unis p4

provided this tool is available (usually it is).

---------- Post updated at 09:14 AM ---------- Previous update was at 09:07 AM ----------

The Notepad++ settings for line endings apply for new files only. If you open existing files, Notepad++ uses the line endings for this file.

You can explicitly change the line endings (EDit/EOLconversion).

With View/ShowSymbol/ShowEndOfLine turned on, Notepad++ will actually show you the EOL character for each line. In addition, if you see in the status line the word "Unix", you know that \n line endings are used for this file.

I guess you mean dos2unix ? And, it may NOT be available all about, not even common linux distributions, but needs to be installed.

Yes, thank you for pointing out the typo. I blame myself, plus the person who puts the S next to the X on the keyboard.

And, that's why I said: "provided it is available", but it is easy to get anyway.

BTW, since the OP is obviously working on Windows for editing, but having Unix as a target platform, he maybe has Cygwin installed too (it would make sense at least), and dos2unix is available as a Cygwin package also. I prefer it over blindly erasing all carriage returns, because if, for whatever reason, an isolated \r appears somewhere in my code, I don't want to go it silently away. It's a matter of taste, of course.