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

**URL:** <https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [December 4, 2018, 10:55am UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877 "2018-12-04T10:55:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [December 4, 2018, 10:55am UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/1 "2018-12-04T10:55:17Z")

</div>

Hi,

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 🙂

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [December 4, 2018, 11:11am UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/2 "2018-12-04T11:11:16Z")

</div>

at least with unix a quick solution:

```auto
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

Otto

---

<div class="post-metadata">

**Author:** ![smgrig](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smgrig/32/19464_2.png) [@smgrig](https://root-forum.cern.ch/u/smgrig)\
**Post date:** [December 4, 2018, 12:50pm UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/3 "2018-12-04T12:50:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [December 4, 2018, 1:08pm UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/4 "2018-12-04T13:08:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [December 5, 2018, 9:05am UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/5 "2018-12-05T09:05:08Z")

</div>

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:

```auto
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

Otto  
[rex5.txt](https://root-forum.cern.ch/uploads/default/original/3X/0/8/08fc40198089215ab087fb4acd4941377bb577e9.txt) (525 Bytes)

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [December 5, 2018, 5:34pm UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/6 "2018-12-05T17:34:05Z")

</div>

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

```

might also work.

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [December 6, 2018, 1:18pm UTC](https://root-forum.cern.ch/t/idea-root-e-convenient-expression-evaluation-in-the-cli/31877/7 "2018-12-06T13:18:05Z")

</div>

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!
