[Toybox] how can we return function result in script

Mingliang HU 胡明亮 mingliang.hu at nio.com
Fri Jun 30 06:18:58 PDT 2023


How can we return function value in script? The "return" doesn't work.
For example:

#!/bin/sh

my_function() {
    echo "Inside my_function"
    return 2
}

my_function
result=$?
echo "Function returned: $result"


The result is:
.: return: No such file or directory
.:  : No such file or directory
.: return: No such file or directory
.: return: No such file or directory
.: return: No such file or directory
.: syntax error '/etc/profile.d/vte-2.91.sh'@40: __vte_osc7


Best regards,
Mingliang


More information about the Toybox mailing list