Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i output commands from a bash script to another shell (python,root)?

Tags:

bash

root

i want to open a shell of a different program from the bash script (specifically root - a software for physicists) and execute several commands in a row.

I know to enter one command:

echo ".L mymacro.C" | root -l  

but i need to enter several commands one by one without closing the root shell (root is not a root user, but an interactive shell for a different program)

I have tried with the parentheses, but it didn't succeed:

(echo ".L mymacro.C"; echo "myClass a";echo "a.Loop") | root -l

I need those 3 commands entered in a root shell one by one:

mymacro.C
myClass a
a.Loop

How could i do this from a bash script?

Thank you very much.

like image 809
Milena Avatar asked Mar 12 '26 21:03

Milena


2 Answers

Perhaps a here document might work:

$ root -l <<EOF
.L mymacro.C
myClass a
a.Loop
EOF
like image 195
mhawke Avatar answered Mar 14 '26 12:03

mhawke


Can you not simply do:

echo -e ".L mymacro.C\nmyClass a\na.Loop" | root -l

This will send the data line by line to the root shell.

Or if you really want to do it one by one, you can always loop as follows:

Code removed thanks to mhawke's remark

like image 42
ShellFish Avatar answered Mar 14 '26 14:03

ShellFish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!