Shell – Pass a command to ROOT from a shell script and having it stay open

cern-rootcommand lineinputshellshell-script

I am writing a bash script to perform some analysis using the program ROOT. I want to run some initial command to load the result of the analysis, then continue using ROOT interactively.

The analysis part goes along well but the problem is that after root is executes my initial command, it closes immediately. So far I have tried the EOF (here-file) construct to pass my initial command and I am a bit unfamiliar with shell scripting so I would like to get your opinions on how to keep ROOT running after the execution of the script. That is I would like to see the ROOT prompt instead of the sytem prompt.

./runReader.py SummerStd 140PU_NM1 
root -l SummerStd_140PU_NM1_his.root << EOF
TBrowser a;
EOF

The above code executes the analysis then runs root; however, it immediately terminates and I have no time to inspect the TBrowser since I have the system prompt instead of the ROOT prompt. I would like control to stay at root's command prompt after the script sends the TBrowser command to the program, so I can enter additional commands by hand.

Best Answer

You could do:

expect -c 'spawn -noecho root -l SummerStd_140PU_NM1_his.root
           send "TBrowser a;\r"
           interact'
Related Question