5

I am having trouble launching an executable that I have created from a shell script. I would like to automate testing by running the program many times with different command line options to verify it is working.

When I type echo $SHELL, /bin/sh is displayed.

The following is my shell script:

#!/bin/sh
clear 
echo "Running first test."
./myProgram
exit 0

When I run the script (sh myScript.sh), with myProgram in the same directory, I see the following output:

Running first test.
: not foundsh: line 4:

When executing the program ./myProgram, it runs as expected with no command line options.

I have also tried: myProgram ./myProgram & myProgram & based on answers to somewhat similar questions, but they all result in the above error message.

4

2 に答える 2

6

あなたの改行は間抜けです。dos2unix修正に使用します。

于 2013-02-12T04:59:44.907 に答える
1

フルパスを使ってみませんか?たとえば、myProgramが/ home / user1 / binにある場合は、。/myProgramの代わりに/home / user1 / bin/myProgramを試すことができます。これは機能するはずです。

パス変数$PATHにパスを追加して、どこからでもmyProgramを直接呼び出すこともできます。

引用符なしでターミナルで「exportPATH=$ PATH:/ home / user1/bin」を実行します。これは、現在のターミナルセッションにのみ影響することに注意してください。パスを永続的に追加する場合は、ホームディレクトリの.bashrcファイルを次の行で更新します。

于 2013-02-12T05:54:26.323 に答える