当我将 defshell 设置为 bash 时,如何更改屏幕中的默认目录?

How can I change default directory in screen when I have defshell set to bash?

我知道您通常可以在 screenrc 文件中使用 chdir 在 运行 执行 screen 命令之前更改目录。但是,如果我设置了 defshell -bash,这对我不起作用。这是一个不起作用的示例文件:

    defshell -bash 
    defscrollback 100000

    hardstatus on
    hardstatus alwayslastline
    hardstatus string "%w%=%m/%d %c"

    chdir /Users/myuser/work
    screen -t "work"

$ screen -c testrc

$ pwd /Users/myuser

注释掉第一行就可以了,但我想 运行 bash shell 在我的屏幕上。如果相关的话,这是在 OSX 上。我的屏幕命令没有别名。

问题是您的 defshell 指定了 login shell,这使得它转到主目录。根据screen's manual

shell command

Set the command to be used to create a new shell. This overrides the value of the environment variable $SHELL. This is useful if you'd like to run a tty-enhancer which is expecting to execute the program specified in $SHELL. If the command begins with a '-' character, the shell will be started as a login-shell.

如果您将其更改为

defshell bash

它不应该那样做。