Search code examples
c++bashfunctionroot-framework

Pass a string variable from bash script to root macro


I am defining a variable in a bash script in order to use it when I call my macro with root, such as:

user = name
root 'macro.C('$user')'

When the macro is executed, I get:

Processing macro.C(name)...
Error: Symbol name is not defined in current scope  :0:
*** Interpreter error recovered ***

My macro is basically defined as

void macro(char* user[])
{
   //code
}

I think the problem might be in this last chunk of code. All I want to do is to have a string/char I can use in my macro. Any idea how to do that?

Thank you in advance!


Solution

  • Bash doesn't perform variable expansion on strings in single quotes ('). Try with double quotes (") instead:

    root "macro.C(\"$user\")"
    

    Edit: escaped the inner string in response to your comment.