Shell batch test

hi,
how to use shell script to test my executable ?
if i have two executable here ,like test1 test2,how to do ?

need help. thanks
Well, that depends on whether these two programs work together or one after the other.

If test1 does something and test2 doesn't need the output from test1, just put them in a file like this:

1
2
3
test1

test2


On the other hand, it test2 need the output of test 1, something like this might be the answer:

1
2
3

test 1 | test2


You didn't say what shell you're using; however, this should work in all of the popular shells (ksh, sh, c, bash, etc.) Also, don't forget to change the modes on your shell script (chmod 744 myscript, for example.)

Hope this helps!
I am using bash in Fedora8


how to track the return value of test1 in bash script?

if 0 indicates ok and -1 error , I use lines like below

ret=./test
echo the test return is $ret

but bash alway complains error .

how to track return value in bash?



1
2
./test #execute the program
echo $? #get return value 

If you've got an error you should say what error you've got.
Last edited on
ne555 is right. Don't forget that $? gets updated on every command; therefore, use it or save it right away. I usually do something like this:

1
2
3
4
5
6
7
8
9

./test

rc=$?

#    Now $? can change all it needs to.


thanks kooth and ne55 for your great help

$? changes each time after you execute an executable file
and can be used to track return code

/*******test1.c********/
1
2
3
4
int main(int argc ,char** argv)
{
     return 111;
}


in bash_test.sh

1
2
3
./test1

echo $?


the result will be 111

Last edited on
Right, but any other command you run in your shell script will effect $? too.

You can try this experiment:

1
2
3
4
5
6
7
8
9
10
11
12
13

#    Run your test1 program:

./test1

echo $?

#    Run the date command:

date

echo $?
Right, but any other command you run in your shell script will effect $? too.


Well, obviously. What you refer to as 'commands' are programs.
Close, but no cigar -- some commands are shell built-in types, which can be functions within the shell and also effect $?.
any program's execution updates $?

no matter the program is built-in or not.

it is true.
Last edited on
Topic archived. No new replies allowed.