2

To help with recovering history across restarts etc I would like to get some key data, like $TERM_SESSION_ID, stored in my command history. This would be preserved when the command response output in screen history is no longer available.

I have tried a number of ways and though the session text shows the TERM_SESSION_ID data it is not stored in the command history:

1014  26/12 22:28:28 echo $TERM_SESSION_ID
1015  26/12 22:44:58 `echo $TERM_SESSION_ID`
1016  26/12 22:45:35 echo ${TERM_SESSION_ID}
1017  26/12 22:45:50 echo `$TERM_SESSION_ID`
1018  26/12 22:46:05 echo `echo $TERM_SESSION_ID`
1019  26/12 22:49:28 echo ${TERM_SESSION_ID}

Although I saw on screen (and do not mind the error messages):

$ echo ${TERM_SESSION_ID}
w3t0p0:5554ACED-B4C5-4E5A-A7C2-F5215ED4F4D7
$ echo `$TERM_SESSION_ID`
-bash: w3t0p0:5554ACED-B4C5-4E5A-A7C2-F5215ED4F4D7: command not found

I do not think this is down to the "info commands" being non bash-valid commands since I get the same sort of results with

1026  26/12 23:08:24 test="ls"
1027  26/12 23:08:27 echo $test
1028  26/12 23:09:03 ${test}

saw output of ls command here, but command recorded is ${test} as typed

Can you tell me how I can get my command history to log/include the data from the shell variable?

For instance:

1029 26/12 23:10:05 ls
1030 26/12 23:10:06 session
w3t0p0:5554ACED-B4C5-4E5A-A7C2-F5215ED4F4D7
  • The command history is the history of executed commands, the way you typed them. What is your goal here, why do you need to keep the value of variables in the history? – nohillside Dec 27 '17 at 5:33
  • History accross sessions is maintained by some clever scripting on Apple‘s part already – nohillside Dec 27 '17 at 5:34
  • I want to ensure I have the best chance of finding old session data across quits and reboots. I believe many log files exist of command history in bash, screen etc but they are not easy to locate when I have 6 UI windows with multiple users logged in (me in different guises) and multiple "screen" subwindows and background processes. So If I can show session id data that is relevant to log file names in my command history then I have direct access to the exact file I require amongst the many. AND... my thanks! – colin Dec 28 '17 at 12:44
  • That is I want to see the file containing the system output as per scroll back, I tend to keep very long scroll back at times for some activities while I clear others regularly. – colin Dec 28 '17 at 12:47
  • In particular (the very great) iTerm2 offers session continuity across crash, force-quit, reboot etc but with multiple windows the assignment of session history to window is pseudo randomly done by the OS. So my command history I keep by TTY does not match the scroll back data. Almost worth finding a way to swap tty session from window A to B by detach/attach but it is tricky on some platforms using dtrace and likely not possible on Darwin/Mac OS – colin Dec 28 '17 at 12:54

You must log in to answer this question.

Browse other questions tagged .