how to get return code in one line

I know how to get the returning code of a function but wonder if I can combine the follwoing two lines into one:
e.g.:
#!/bin/shell
...
#line 1
MyFunction arg1 arg 2
#line 2
rec=$? #this will be evaluated later
....

like in c/c++, we'd write one line:
rec=MyFunction(arg1, arg 2)

Because I have many of those funciton calls in one script where all return codes need to be collected & evaluated later. It'd look nicer with one less line here.

Thanks in advance.

The one thing that is hard to do is make shell look nice.

The closest you can get is

if do_my_thing ....
then
       echo it worked
fi

but you don't get the exit code into a variable.

very neat! I tested it & looks the if statement evaluates if the returning code is 0 or not, isn't it??

However, I failed to make it to check if it is non-zero- tried a few syntax with no luck... such as: if [ ! domything ], if [ domything -ne 0 ].... can you make it?:wink:

No alas, I haven't. However some programs can reverse the return code, eg grep with the -v option.

There is a program called "true" and one called "false", there should be one called "not"....

#!/bin/sh
if $@
then 
    exit 1
fi
exit 0

then you could do

if not myprogram
then
.....

now you lost me- what is $@ ?

all the variable arguments except $0, useful as $0 is normally the script name, I'm suggesting that the first CODE block be put in a file called "not".

wow... thank you "Porter"- or whoever you really are;-)
I've been doing a program with this new language in last couple of weeks. Now I'm really interested in learning more! I want to be as good as you one day... oh well, just wishful thinking;-)