7

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.

1
  • Are myScript.sh and myProgram in the same directory. If so, try simply changing to that directory and running ./myScript.sh (ie. without the first sh). Also, posting on Unix and Linux might help you out.
    – Mr Moose
    Commented Feb 12, 2013 at 5:01

2 Answers 2

7

Your newlines are goofed. Use dos2unix to fix.

3

why don't you try using the full path? e.g., if myProgram is in /home/user1/bin, you can try /home/user1/bin/myProgram instead of ./myProgram. This should work.

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.