Search code examples
yoctoyocto-recipeyocto-layeryocto-dunfell

Variables handling in bb receipe yocto


I want to edit a variable in do_compile() task but I get the error "VAR: not found" when I try to modify the value.

A litte example of this:

    MY_CUSTOM_VAR = "some_value"
     
    do_configure() {
        echo "Configuring with MY_CUSTOM_VAR=${MY_CUSTOM_VAR}"
        MY_CUSTOM_VAR = "new_value"
        echo "Modified MY_CUSTOM_VAR: ${MY_CUSTOM_VAR}"
    }

Log data follows:

    | DEBUG: Executing shell function do_configure
    | Configuring with MY_CUSTOM_VAR=some_value
    | /../run.do_configure.13840: 103: MY_CUSTOM_VAR: not found

...So echo works but I can't assign a new value.

Can someone explain to me what is wrong?


Solution

  • The do_configure() function is in shell, so the variable assignment must be done without spaces:

    MY_CUSTOM_VAR="new_value"
    

    Otherwise, the shell interpreter believes you are launching command MY_CUSTOM_VAR with two parameters = and "new_value". Example, in a shell interpreter:

    $ MY_CUSTOM_VAR = "new_value"
    MY_CUSTOM_VAR: command not found
    

    But the following works:

    $ echo $MY_CUSTOM_VAR
    
    $ MY_CUSTOM_VAR="new_value"
    $ echo $MY_CUSTOM_VAR
    new_value