本文来自依云's Blog,转载请注明。
上篇说到,我在Arch下的tmux的部分环境变量有问题。于是接下来我开始调查原因。最后终于真相大白。不过在揭露真相前,先详细说说问题是什么。
自从使用zsh以后,我在Ubuntu下发现我在~/.profile
中设置PATH变量的代码在tty下没有起作用。但在~/.zshrc
中设置又不行,因为图形界面登录时不会读取~/.zshrc
。source 它也不行,因为可能导致双重设置(在一段时间里,我总是很奇怪地发现命令补全时某些命令会出现两次。。。)。于是,最后我的方案是这样的(箭头表示 source):
.profile --> .zsh/zshrc.env <-+ .zshrc --> ZSHRC_ENV set? --No--+
这个方案在Ubuntu下一直工作良好。但在Arch+tmux下就出问题了。在tmux中的zsh启动前,ZSHRC_ENV
已经设置,于是~/.zsh/zshrc.env
没有被 source,于是$PATH
设置得不对了。。。
在查阅tmux N次之后,我想,可能是某个启动文件覆盖了我自己的 PATH 变量的设置。于是打开 zsh 的文档,翻到这里:
5.1 Startup/Shutdown Files
Commands are first read from /etc/zsh/zshenv; this cannot be overridden. Subsequent be- haviour is modified by the RCS and GLOBAL_RCS options; the former affects all startup files, while the second only affects global startup files (those shown here with an path starting with a /). If one of the options is unset at any point, any subsequent startup file(s) of the corresponding type will not be read. It is also possible for a file in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and GLOBAL_RCS are set by default.
Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zsh/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zsh/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zsh/zlogin and $ZDOTDIR/.zlogin are read.
于是发现这一切的根源在于tmux里启动的是login shell!Arch的/etc/profile
中重置了$PATH
、/etc/profile.d/locale.sh
中重置了$LANG
,所以造成我的tmux下的zsh环境变量不对的问题。于是我把设置移回了~/.profile
中,然后将软链接~/.zprofile
指向它。locale.sh
pacman不知道是什么包的,所以我就把它改成了:
[ -z "$LANG" ] && export LANG=en_US.UTF-8
至此,tmux部分的问题终于解决了!
May 10, 2011 02:41:40 PM
忽然想起来了,上次我去武汉的时候,还经过武汉大学了。对面不远好像有个 华中农业大学吧,还是什么大学不记得了。
Aug 18, 2011 10:36:40 AM
您好,我想请问下,tmux的进入复制模式和粘贴对应的命令是什么?
就是默认的"[","]",我想修改下这两个建设置,但是找不到对应的命令。
谢谢哈~
Aug 18, 2011 04:43:34 PM
你用 <prefix>? 查看帮助就知道啦:
bind-key [ copy-mode
bind-key ] paste-buffer
Aug 15, 2014 07:32:29 PM
## Session initialization
## avoid starting a login shell
set -g default-command "${SHELL}"
## update necessary environment variables, for fbterm's 256color support in vim, ssh and etc
set -g update-environment 'fbterm DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY'
## workaround: determine if running in a X session(xterm), if true enable 256color support
if '[[ -n "${DISPLAY}" ]]' 'set -g default-terminal screen-256color'
## End of session initialization
-------
第三行的配置就可以打開非登錄shell了;另外似乎沒在乃的github上找到zshrc呢……一直想參考一下來着
Aug 15, 2014 08:03:17 PM
在这里: https://dl.dropboxusercontent.com/u/1372730/zshrc
Aug 16, 2014 07:21:58 AM
多謝 :)
Oct 14, 2019 11:18:59 AM
好的,仙子。我要改改我的`sudo su -i`陋习了。
新建的文件中使用`cat foo.txt | wc -l`显示的数量是0.
而在新建的空文件夹中使用`ll | wc -l`显示的数量是1。
为什么是1?我想不通。
man wc
```
Oct 14, 2019 01:01:02 PM
因为 ls -l 会显示个「总用量 0」呀。
Dec 17, 2020 11:07:44 AM
五大对面是华中师范大学哈