首页 日常

在shell中有一个名为.logout的设置文件。 当用户退出时.logout中的命令被执行

在用户的.profile加入下面这行代码,如果用的是zsh应该在.zprofile中添加,如果用的是bash应该在.bash_profile中添加

trap '. ~/.zsh_logout;exit' 0

将退出时想运行的命令放入~/.zsh_logout中

pwd > ~/.last_wd.txt
# 上面命令不行的话试试用下面这个
# echo $PWD > ~/.last_wd.txt

这个命令是把退出时的目录放到.last_wd.txt中,所以要先确保有这个文件,没有的话创建一个
touch ~/.last_wd.txt

然后在.zshrc中读取路径并cd到那个位置

cd `cat ~/.last_wd.txt`

注意:使用cat ~/.last_wd.txt使用反单引号包裹,不是单引号



文章评论

    赵红博其 访客ChromeWindows
    2023-01-12 19:29   回复

    zsh?