Shell in interactive ROOT

Hi,

We can use shell commands in ROOT, by prepending the commands with “.!”. Piping and stuff works as well, which is wonderful. However, I wonder how can we mix regular ROOT - I’m sure I’m just forgetting the proper phrase - and shell commands in a single line.

Basically, how can I get something like .! _file0->ls() | grep exp to work? I’ve tried various permutations and all of them makes either sh or the interpreter scream.

Cheers,
Afiq

Hi,
I think ROOT’s .! is “dumber” than you think: it just takes whatever commands you write after it and executes them in a shell (spawned as a subprocess if I’m not mistaken). Something like .! _file0->ls() | grep exp would require that what you put after .! is parsed to check which parts look like C++ and which parts look like bash…I’m not even sure it’s possible in general.

Something you can do is the following, from your terminal:

$ root file.root -l -b -q -e '_file0->ls()' | grep exp

(which could be simplified using a bash alias, e.g. rootexec arg1 arg2 for root arg1 -l -b -q -e arg2).

Cheers,
Enrico

1 Like

A brilliant way of combining what’s already available. Never occurred to me to craft it so. Exactly what I’m looking for, thanks a lot.

Cheers,
Afiq

Glad I could help.
Note that for _file0->ls() specifically you can directly use, again from terminal, rootls.

Cheers,
Enrico

rootls appears to have been written in python, which I don’t grab by default in my “bare” setup. Thanks for the tip nonetheless!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.