[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A snapshot
Re: A snapshot
Wed, 03 Jun 2020 04:47:11 -0700
Greg Wooledge <email@example.com> writes:
>On Sat, May 16, 2020 at 09:10:07AM -0700, firstname.lastname@example.org wrote:
>> I would like to create a file -- call it "snapshot" -- that will record
>> like the current command history and the value of all shell and env
>> And, then, at a later time, possibly from a different terminal and invocation
>> of bash, access the file, so that to the extent practicable, it will be as
>> though I continued the bash session at the time of snapshot's creation.
>Well... there are several things you'll need to save in a machine-readable
>format. The challenge is thinking of everything.
>The 'declare -p' command gets you machine-readable copies of all shell
>and environment variables, but not functions. The 'declare' commands
>gets you variables and functions, but is missing the distinction between
>shell and environment variables. I'd probably go with 'declare -p' for
>the variables, and then pick up the functions separately.
>So, then 'declare -pf' for functions.
>'alias' for aliases.
>'shopt -p' for shell options.
>I'll let you figure out how to get shell history. Maybe setting HISTFILE
>to a temporary file, and keeping that separate from the other settings?
>History is just a mess, and is not one of the things I've spent a lot of
>time trying to wrap my head around.
>Maybe 'stty -a' to save the terminal state? But I doubt you'd want to
>restore the terminal in a nonstandard state anyway.
>Of course, you will lose all running child processes, but I'm assuming
>you've already come to terms with that.
Thank you and Mr. Maroloccio very much. I now have bash functions that save
and restore snapshots. They don't save everything but they save all that I
Once I read the bash man page carefully enough, saving and restoring the
command history was trivial ("history -w" and "history -r" do it.). But I had
to read the possibly relevant parts of the man page, several times before I
found what I needed.