KSH shell脚本不会执行并返回127(未找到)

时间:2021-02-09 16:09:50

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 nearly identical to another script which works just fine. I can't see any differences between the two in terms of permissions or ownership.

这几乎与另一个运行良好的脚本相同。我看不出两者在许可或所有权方面有什么不同。

4 个解决方案

#1


4  

There may be 2 problems:

可能有两个问题:

  • Shebang line is wrong (as ghostdog alluded to)

    Shebang line是错误的(正如ghostdog所暗示的)

  • The script was saved from Windows and has DOS line endings.

    该脚本从Windows中保存,并有DOS行尾。

For the latter, do

对于后者,做

head padaddwip.ksh | cat -vet | head -1

The command should produce the shebang line NOT ending with ^M. If it does end with ^M that's a DOS-encoded file, and the fix is:

命令应该产生shebang行而不是以^ M。如果真的结束^ M DOS-encoded文件,和解决办法是:

cp padaddwip.ksh padaddwip.ksh.bak
dos2unix padaddwip.ksh.bak > padaddwip.ksh
./padaddwip.ksh

On systems without dos2unix, you can use

在没有dos2unix的系统上,您可以使用

cat padaddwip.ksh.bak | tr -d "\r" > padaddwip.ksh

#2


1  

just a guess, check your shebang in padaddwip.ksh. it should be something like #!/bin/ksh. If not, use which ksh to see where your ksh is installed. Alternatively, you can execute your script by calling the interpreter(ksh) eg

猜一猜,用padaddwid .ksh检查你的shebang。应该是#!/bin/ksh之类的。如果没有,使用哪个ksh查看ksh安装在哪里。或者,您可以通过调用解释器(ksh) eg来执行脚本

$ /bin/ksh padaddwip.ksh

美元/bin/ksh padaddwip.ksh

another way you can do is changing your shebang to #!/usr/bin/env ksh

另一种方法是将shebang改为#!/usr/bin/env ksh

Also, make sure the user executing the script has its primary group as btgroup

此外,确保执行脚本的用户的主组为btgroup

#3


1  

Another way to rid your scripts of the annoying ^M characters would be to open the file in vi and type :%s/^M//g (sed within vi) where the ^M here is created by typing Ctrl-V then Ctrl-M. I personally like this method because you don't need to create a backup file and you instantly see the results -just an OCD habit of mine-

另一种脚本摆脱恼人的M ^字符将在六世和打开文件类型:% s / M ^ / / g在vi(sed)M ^这是由输入ctrl - v然后Ctrl-M。我个人喜欢这个方法,因为您不需要创建一个备份文件,您可以立即看到结果——这只是我的OCD习惯—

Also, I have had some weird problems with using tr and control characters such as \r it may have been a shell or site-specific issue, but in such cases I needed to use either the above method or sed from the command line...very to similar what DVK shows above; like sed -e 's/^M//g' padaddwip.ksh.bak > padaddwip.ksh where you create the ^M by doing Ctrl-V then Ctrl-M (when in vi editor mode).

此外,我在使用tr和控制字符(如\r)时遇到了一些奇怪的问题,这可能是一个shell或特定于站点的问题,但是在这种情况下,我需要使用上面的方法或命令行中的sed……与上面DVK显示的非常相似;像sed - e ' s / M ^ / / g padaddwip.ksh。贝克> padaddwip。ksh,你创建通过ctrl - v ^米然后Ctrl-M(在vi编辑器模式)。

#4


0  

the shebang is bad.

那是不好的。

test the scenario with the shell interpreter on the cmdline.

在cmdline上使用shell解释器测试该场景。

ksh padaddwip.ksh

#1


4  

There may be 2 problems:

可能有两个问题:

  • Shebang line is wrong (as ghostdog alluded to)

    Shebang line是错误的(正如ghostdog所暗示的)

  • The script was saved from Windows and has DOS line endings.

    该脚本从Windows中保存,并有DOS行尾。

For the latter, do

对于后者,做

head padaddwip.ksh | cat -vet | head -1

The command should produce the shebang line NOT ending with ^M. If it does end with ^M that's a DOS-encoded file, and the fix is:

命令应该产生shebang行而不是以^ M。如果真的结束^ M DOS-encoded文件,和解决办法是:

cp padaddwip.ksh padaddwip.ksh.bak
dos2unix padaddwip.ksh.bak > padaddwip.ksh
./padaddwip.ksh

On systems without dos2unix, you can use

在没有dos2unix的系统上,您可以使用

cat padaddwip.ksh.bak | tr -d "\r" > padaddwip.ksh

#2


1  

just a guess, check your shebang in padaddwip.ksh. it should be something like #!/bin/ksh. If not, use which ksh to see where your ksh is installed. Alternatively, you can execute your script by calling the interpreter(ksh) eg

猜一猜,用padaddwid .ksh检查你的shebang。应该是#!/bin/ksh之类的。如果没有,使用哪个ksh查看ksh安装在哪里。或者,您可以通过调用解释器(ksh) eg来执行脚本

$ /bin/ksh padaddwip.ksh

美元/bin/ksh padaddwip.ksh

another way you can do is changing your shebang to #!/usr/bin/env ksh

另一种方法是将shebang改为#!/usr/bin/env ksh

Also, make sure the user executing the script has its primary group as btgroup

此外,确保执行脚本的用户的主组为btgroup

#3


1  

Another way to rid your scripts of the annoying ^M characters would be to open the file in vi and type :%s/^M//g (sed within vi) where the ^M here is created by typing Ctrl-V then Ctrl-M. I personally like this method because you don't need to create a backup file and you instantly see the results -just an OCD habit of mine-

另一种脚本摆脱恼人的M ^字符将在六世和打开文件类型:% s / M ^ / / g在vi(sed)M ^这是由输入ctrl - v然后Ctrl-M。我个人喜欢这个方法,因为您不需要创建一个备份文件,您可以立即看到结果——这只是我的OCD习惯—

Also, I have had some weird problems with using tr and control characters such as \r it may have been a shell or site-specific issue, but in such cases I needed to use either the above method or sed from the command line...very to similar what DVK shows above; like sed -e 's/^M//g' padaddwip.ksh.bak > padaddwip.ksh where you create the ^M by doing Ctrl-V then Ctrl-M (when in vi editor mode).

此外,我在使用tr和控制字符(如\r)时遇到了一些奇怪的问题,这可能是一个shell或特定于站点的问题,但是在这种情况下,我需要使用上面的方法或命令行中的sed……与上面DVK显示的非常相似;像sed - e ' s / M ^ / / g padaddwip.ksh。贝克> padaddwip。ksh,你创建通过ctrl - v ^米然后Ctrl-M(在vi编辑器模式)。

#4


0  

the shebang is bad.

那是不好的。

test the scenario with the shell interpreter on the cmdline.

在cmdline上使用shell解释器测试该场景。

ksh padaddwip.ksh