[Toybox] Bug: can't execute a shell function via variable in toybox shell

Bird, Tim Tim.Bird at sony.com
Thu Feb 27 12:45:28 PST 2025


Hey Rob,

I indirectly reported this on a separate thread, but here's a more complete bug report,
with steps to reproduce.

If I define a shell function in bash, I can execute the function by putting its name
in a variable, and then retrieving the value of the variable at the shell interpreter prompt,
like so:

On my desktop machine, running the bash shell:
tbird at timdesk:~$ myfunc() {
> echo "inside myfunc"
> }
tbird at timdesk:~$ myfunc
inside myfunc
tbird at timdesk:~$ VAR="myfunc"
tbird at timdesk:~$ $VAR
inside myfunc

This doesn't work with the toybox shell.  I get "sh: <func_name>: No such file or directory"

When running a toybox shell under qemu, I get the following:
$ myfunc() {
> echo "inside myfunc"
> }
$ myfunc
inside myfunc
$ VAR="myfunc"
$ $VAR
sh: myfunc: No such file or directory
$ 

Note that executing an internal or external command from a variable reference works:
$ VAR="echo hello"
$ $VAR
hello
$ VAR="cat /etc/passwd"
$ $VAR
root:x:0:0:root:/root:/bin/sh
guest:x:500:500:guest:/home/guest:/bin/sh
nobody:x:65534:65534:nobody:/proc/self:/dev/null
$ 

Thanks,
 -- Tim



More information about the Toybox mailing list