Re: Shell function doesn't return correct value over 255?
mike wrote:
>>From all material I collected a shell function returned value is kept
> in $? without any limit, but I got some weird problems. Here is a
> example:
>
> --------------------------
> #!/bin/sh
> ###!/bin/bash
>
> add1() {
> x=`expr $1 + 1`
> #echo -e "x=$x"
> return $x
> }
>
> [...]
>
> a=1026
> add1 $a
> echo -e "a=$a\t$?"
ugly workaround with subshell:
--- cut here ---
#!/bin/bash
add1() {
x=`expr $1 + 1`
#echo -e "x=$x"
echo $x # changed
}
[...]
a=1026
ret=$(add1 $a) # changed
echo -e "a=$a\t$ret" # changed
--- cut here ---
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
|