指定默认shell/登录shell/登录zsh shell后自动运行脚本/配置文件/zsh的配置文件/查看当前shell
文章目录
指定默认shell/登录shell/登录zsh shell后自动运行脚本/配置文件/zsh的配置文件
查看当前shell
-
How do I find out what shell I am using on Linux/Unix? - nixCraft (cyberciti.biz)
-
ps -p $$
:Display your current shell name reliably.-
cxxu@cxxuAli:~$ ps -p $$ PID TTY TIME CMD 5586 pts/0 00:00:00 bash
-
-
echo "$SHELL"
– Print the shell for the current user but not necessarily the shell that is running at the movement.-
# cxxu @ cxxuAli in ~ [8:22:33] $ echo "$SHELL" /bin/zsh
-
-
echo $0
– Another reliable and simple method to get the current shell interpreter name on Linux or Unix-like systems.-
# cxxu @ cxxuAli in ~ [8:22:43] $ echo $0 -zsh
-
-
指定默认shell
如果没有想要的shell,可以自行安装,再设置默认
对于已有的shell,细节如下:
查看本机可用shell
cxxu@cxxuAli:~$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/bash /bin/rbash /bin/dash /bin/zsh /usr/bin/zsh
查找指定shell
- 例如查找powershell是否已经安装:
$ cat /etc/shells|grep powershell /opt/microsoft/powershell/7/pwsh
指定默认shell
- 例如,根据上述查询,选择一个心仪的shell作为
chsh -s
的参数(绝对路径)
chsh -s /bin/bash
登录zsh 后自动运行脚本文件
- 下方的参考列出了不同的zsh配置文件,以及触发运行配置文件的时机
- bash 也有自己一套配置文件体系,可以查看官方文档/资料
zsh的配置文件
-
man zsh
中末尾介绍了一些zsh的配置文件 -
Moving to zsh, part 2: Configuration Files – Scripting OS X
-
all users user login shell interactive shell scripts Terminal.app /etc/zshenv
.zshenv
√ √ √ √ /etc/zprofile
.zprofile
√ x x √ /etc/zshrc
.zshrc
√ √ x √ /etc/zlogin
.zlogin
√ x x √ /etc/zlogout
.zlogout
√ x x √
-
不同shell共用配置文件
- 需要声明,不要过分要求bash和zsh使用同一份配置文件,bash,zsh的配置文件体系不同,
- 我们只好分开处理,毕竟,你也就用这一两种shell,配置一次,几乎是一劳永逸,花费过多时间求统一,不仅兼容性得不到保证,而且耗费不必要的时间!
- 不过我想到了一种可能的共用统一份配置方案,就是参考zsh的配置文件的命名,对bash的配置文件配置一个硬链接,这样维护一份文件就可以.
ln -P .profile .zprofile
- 不过通过导入配置的方式,本身就已经有很高的重用性
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了