0

I've been using screen's chdir command to set a new working directory for new screen windows, more on that later. What I need to do is find out what the setting was before I set it, so that I can set it back. I can do this experimentally by starting a new session and echoing out $PWD but I can't seem to do this more concretely in a way that I can grab and store the value in a script. I feel like there's probably some command in the very detailed man page that will accomplish this, but I haven't found it yet.

Now to explain what I'm doing specifically that calls for this:
I have a script that starts up about 4 processes in parallel, it turns out to be very handy to have them each start in their own screen window. In the bash script it's easy to determine I'm running the script within screen with this test: if [[ $TERM =~ screen* ]]; then there's other ways, but this one is fine. In the script I can then execute screen -x -X screen process1. This attaches to the current session in multiuser mode and asks it to open a new screen window running the process. It's necessary from within the script, because without -x it'll complain that the current command isn't run in a terminal, which is about right, it's not interactive. Anyway, the process1 needs to run in a particular path. Not just one, but one of any four or five where different versions of process1 are. I'm running the script from that path. But screen often isn't started from that path, so process1 will start in a new working directory set to wherever screen was started. No problem though, just execute screen -x -X chdir $PWD before starting process1 (2, 3, and 4) and you're now in the right path. However you've permanently changed screen's default working path for a new window, this will upset the user (me, and some colleagues). So it should be no problem to issue screen -x -X chdir $oldCHDIR before exiting. However, I can't seem to find out what $oldCHDIR was, and frankly it could be anything, nothing so simple as it definitely being $HOME. If you're still reading and wondering what my question was, it was the one in the first paragraph, how can I find out screen's current chdir setting.

4
  • Why not start a subshell before changing? Aug 13, 2012 at 4:46
  • Starting a subshell would let you change the directory in the subshell and leave screen alone. Aug 13, 2012 at 4:56
  • So I'd call: screen -x -X screen bash -c 'cd '$PWD';process1'. That'd work. It's a workaround to finding out the chdir setting, which I feel like should be possible somewhere.
    – dlamblin
    Aug 13, 2012 at 5:10
  • Of course now no one will answer the actual question. This is why you should never explain yourself. I don't really want to JUST solve this ONE problem. I want to know, as a question, can I get a setting like what chdir is set to out of screen. The answer can be yes, here's how or no. All too often I'm getting these: why not do something totally different. That's fine when there's a great reason to. But in this case it slows down the startup to each process and it uses more memory.
    – dlamblin
    Aug 13, 2012 at 14:54

0

You must log in to answer this question.

Browse other questions tagged .