I want to save my all terminal outputs. If I run "script" command from some terminal session it works fine. But if I put in .bashrc file, then .bashrc file keeps loading again and again
Script started, output log file is 'typescript'.
Script started, output log file is 'typescript'.
Script started, output log file is 'typescript'.
Script started, output log file is 'typescript'.
I tried this solution where command is skipped second time by setting local variable. https://unix.stackexchange.com/a/323920/381656
This also creates problem. If I run this command from simple terminal it works fine. But if I put in .bashrc then it always changes present directory into home directory. For example if I use split screen in terminator, then instead of opening in that directory it opens in home directory.
Is there a way to make .bashrc command run similarly as I run from active terminal session.
Update
After some hit and trial, I found out what was problem, why it was not opening in same directory.
Lets say if I open terminal in /abc/xyz. Now when script is executed then new shell is launched. If I change location of this shell it will not effect original terminal. Original terminal still holds location /abc/xyz. And if I try to split screen or open new tab, then parameter of current directory is taken from parent shell not from shell of script.
Parent shell's environment variable "PWD" needs to be updated as child shell for correct result. But as mentioned in this other question, it is not possible.
Is it possible to pass environment variables from child to parent in user space?
One possible hack would be using a text file for storing current directory, and while opening new tab updating to that location.
xterm -l
, you will see that a Xterm file will popup in your home directory with the terminal contents.