LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Running Executable in Bash Script (https://www.linuxquestions.org/questions/linux-general-1/running-executable-in-bash-script-871374/)

Duo11 03-27-2011 11:43 PM

Running Executable in Bash Script
 
Hey guys, so I've been trying to write a bash script called runSorter.sh that runs an executable that also takes in some parameters and outputs the results to a text file. The executable, sorter, takes in a number parameter. I want to make it so that you can input as many number parameters into runSorter.sh as you want and it will run the sorter executable for each one. So far, what I have looks like this:

#!/bin/bash
args=("$@")
INDEX=0

if [ -z args ]; then
echo "Error"

else
while [ $# -gt $INDEX ]; do
NUM=${args[$INDEX]}
echo $NUM
echo ./sorter $NUM
let INDEX=INDEX+1
done
fi


My problem is that when I run ./run-sorter.sh 100 on my terminal, it just prints this to the screen:
./sorter 100

How can I have so that it properly executes sorter and outputs everything to a text file? Thanks in advance.

quanta 03-28-2011 12:02 AM

Change this:
Code:

echo ./sorter $NUM
to
Code:

./sorter $NUM

Duo11 03-28-2011 12:14 AM

Quote:

Originally Posted by quanta (Post 4305770)
Change this:
Code:

echo ./sorter $NUM
to
Code:

./sorter $NUM

Hmmm, that works but now it prints sorter's results on another line. How do I get it to print the results on the same line as echo $NUM?

quanta 03-28-2011 01:37 AM

Change `echo $NUM` to `echo -n $NUM`.

Duo11 03-28-2011 01:46 AM

Oooh, I see. Thank you very much.


All times are GMT -5. The time now is 01:45 AM.