[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A snapshot

From: Greg Wooledge
Subject: Re: A snapshot
Date: Sat, 16 May 2020 22:27:26 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Sat, May 16, 2020 at 09:10:07AM -0700, address@hidden wrote:
> I would like to create a file -- call it "snapshot" -- that will record things
> like the current command history and the value of all shell and env variables.
> 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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]