I'm looking for a way to run commands from one bash script to 2 different terminals.
I know a way to do it manually by typing "tty" in one terminal and then redirecting the commands from the other terminal with the "tty" output.
But I would like to do it automatically with a script which can save in a variable the output of "tty". Basically I want to launch a script in a terminal which launches a program in another one and print monitoring messages to follow its activity.
I tried :
gnome-terminal -e "bash -c 'term2=$(tty)' ;exec bash'"
gnome-terminal -e "bash -c 'tty > term2.txt;my_var='cat term2.txt' ;exec bash'"
But none of them is able to save the output of "tty" in my variable. Which I don't understand because it works if I type them manually one by one.
Could you please explain me what is wrong with my method? If you have any suggestions or other methods to propose I'll be glad to learn new things.