KSH shell script won't execute and returns 127 (not found)
Can anyone enlighten me why the following won't work?
$ groups
staff btgroup
$ ls -l
total 64
-rw-rw---- 1 sld248 btgroup 26840 Apr 02 13:39 padaddwip.jks
-rwxrwx--- 1 sld248 btgroup 1324 Apr 02 13:39 padaddwip.ksh
$ ./padaddwip.ksh
ksh: ./padaddwip.ksh: not found.
$ echo $?
127
This is almost identical to another script that works great. I don't see any difference between the two in terms of permissions or ownership.
a source to share
There can be two problems:
-
Shebang's string is incorrect (as a ghost pointer)
-
The script was saved from Windows and has DOS line endings.
For the last do
head padaddwip.ksh | cat -vet | head -1
The command should print a shebang NOT line ending with ^M
. If it ends with ^M
that DOS encoded file and the fix is:
cp padaddwip.ksh padaddwip.ksh.bak
dos2unix padaddwip.ksh.bak > padaddwip.ksh
./padaddwip.ksh
On systems without dos2unix, you can use
cat padaddwip.ksh.bak | tr -d "\r" > padaddwip.ksh
a source to share
just guess check your shebang in padaddwip.ksh
. it should be something like #!/bin/ksh
. If not, use which ksh
to find out where yours is installed ksh
. Alternatively, you can execute your script by calling the interpreter (ksh), for example
$ /bin/ksh padaddwip.ksh
another way you can do it is to change your shebang to #!/usr/bin/env ksh
Also, make sure the user executing the script has their main group as btgroup
a source to share
Another way to save your scripts from annoying characters ^M
is to open the file in vi and type :%s/^M//g
(sed inside vi) where ^M
it is created here by typing Ctrl-V
then Ctrl-M
. I personally like this method because you don't have to create a backup file and you see the results right away - it's just my OCD habit -
Also, I had some weird usage tr
and control chars such as \r
maybe it was a shell or site issue, but in such cases I needed to use either the above method or sed from the command line ... very similar to what DVK shows above; for example sed -e 's/^M//g' padaddwip.ksh.bak > padaddwip.ksh
where you create ^M
by doing Ctrl-V
then Ctrl-M
(in vi editor mode).
a source to share