Executing an executable from a Script shell

I am having trouble running an executable that I created from a shell script. I would like to automate testing by running the program many times with different command line parameters to make sure it works.

When I type echo $SHELL

, is displayed /bin/sh

.

Below is the shell script:

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

      

When I run script ( sh myScript.sh

), myProgram

in the same directory, I see the following output:

Running first test.
: not foundsh: line 4:

      

When executed, the program ./myProgram

runs as expected without command line parameters.

I've also tried: MyProgram. / myProgram & myProgram & based on answers to somewhat similar questions, but they all lead to the above error message.

+3


source to share


2 answers


Your newlines are muted. Use dos2unix

to fix.



+4


source


why don't you try using the full path? for example, if myProgram is in / home / user 1 / bin, you can try / home / user 1 / bin / myProgram instead of. / myProgram. This should work.

You can also add the path to the path variable, $ PATH and call myProgram directly from anywhere.



Run "export PATH = $ PATH: / home / user1 / bin" on your terminal without quotes. Note that this only affects the current session session. If you want to permanently add the path, update the .bashrc file in your home directory with the following line:

+1


source







All Articles