Idea: `root -E`, convenient expression evaluation in the cli


I often find myself using the fantastic root -l -b -q -e 'std::cout << "Hello World!" << std::endl;' to quickly try things out or when debugging to quickly narrow down an issue.

However, I find it cumbersome to have to write the -l -b -q -e part repeatedly when semantically I want to perform a single action (“Just print the result of the expression!”) as opposed to the 4 actions the required options suggest (“Print the result of the expression, but don’t use graphics, don’t show the splash screen, and please quit after the evaluation”).

Hence I propose to introduce the shorthand root -E for this command. Thoughts?

Note: The -b could possibly be omitted from this discussion.
Note: Of course I can use a shell alias for this but this could be useful for people other than I as well :slight_smile:

at least with unix a quick solution:

alias rex="root -n -l -b -q -e "
rex 5./8                                                                                 
(double) 0.62500000   

note I added -n, dont execute rootlogons
But what you propose would be very useful


1 Like

it does not work in ROOT 5.34, rex 5./8 gives:
Warning in TApplication::GetOptions: macro 5./8 not found

thats correct, root 5 has no -e
But since 5 is frozen you wont get the above shortcut I guess

For fans of Root5:
Attached a little bash script which simulates the -e option of Root6.
Copy it to your bin directory, rename to rex5 and “chmod +x rex5”
Then you can do:

rex5 "sqrt(100)"
rex5 56.89*45./6

Dont forget the “” if the expression contains characters
eaten by the shell otherwise.
You see its pretty clumsy and probably not complete.

So another good reason to change to Root 6

rex5.txt (525 Bytes)

cat ${1} | root -n -l -b 

might also work.

I take it then that while the shorthand can be useful, there is not enough motivation to spend development time integrating it into root6.

Thanks for the discussion!