shell-Startup-Files

1. 相关阅读
2. 主流shell
3. shell实例类型
4. Shell启动文件的必要元素
4.1 路径: 命令路径,
4.2 提示符
5. 主流shell的配置文件
6. 默认的bash
6.1 手册
6.2 bash启动文件
6.3 提示符
7. 友好的fish
7.1 简介
7.2 查看帮助文档
7.3 fish的配置
8. zsh

1. 相关阅读

https://www.cnblogs.com/sztom/p/11349159.html
shell脚本

https://szosoft.blogspot.com/2019/07/console-terminal-tty-shell-kernel.html
https://www.cnblogs.com/sztom/p/11247883.html
Console-terminal-tty-shell-kernel
Shell在计算机系统中的位置

http://hyperpolyglot.org/unix-shells
常用shell语法对照(Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh)

https://en.wikipedia.org/wiki/Comparison_of_command_shells

https://opensource.com/business/16/3/top-linux-shells
Linux的前5个开源命令shell

https://www.ibm.com/developerworks/cn/aix/library/au-spunix_fish/index.html
Friendly Interactive Shell(fish)对于 UNIX 新手和专家都很适合

https://wiki.archlinux.org/index.php/Command-line_shell
https://wiki.archlinux.org/index.php/Command-line_shell#POSIX_compliant
https://wiki.archlinux.org/index.php/Command-line_shell#Alternative_shells

https://en.wikipedia.org/wiki/Unix_shell
https://en.wikipedia.org/wiki/Unix_shell#Configuration_files

https://wiki.gentoo.org/wiki/Shell
https://wiki.gentoo.org/wiki/Shell#Available_software

https://en.wikibooks.org/wiki/Bash_Shell_Scripting

https://developer.ibm.com/tutorials/l-linux-shells/

2. 主流shell

Name Description POSIX License user
bash
(默认)
The Bourne Again Shell, is the default shell on Gentoo. It is used by Portage, Gentoo's default package manager. 符合 compliant GPLv3 54%
fish
(友好)
The Friendly Interactive Shell. (2005) Alternative 替代 GPLv2… 12%
zsh
(极客)
An advanced shell that is the chosen interactive shell for many users. 符合 compliant MIT, GPL 23%
tcsh an enhanced version of the Berkeley C Shell (csh). Alternative 替代 BSD 3%
ksh The Original Korn Shell, 1993 revision (ksh93). 符合 compliant Eclipse Public 3%
Other       5%
 

https://developer.ibm.com/tutorials/l-linux-shells/#unix-shells-since-1977
https://developer.ibm.com/developer/tutorials/l-linux-shells/images/figure1.gif

3. shell实例类型

大类 小类 系统配置文件 用户配置文件
交互式 登录shell (初始shell) /etc/profile .bash_profile;
.bash_login;
.profile …
交互式 非登录shell /etc/bash.bashrc .bashrc
非交互式 运行shell脚本的shell等 通常不读取启动文件  

4. Shell启动文件的必要元素

路径,提示符,别名alias,权限掩码(077;022)

4.1 路径: 命令路径,

/usr/local/bin
/usr/bin
/bin
这个顺序可以确保/usr/local中的特定变体覆盖默认程序。
大多数Linux发行版中,几乎所有软件包都会被安装到/usr/bin中。也有少数情况(游戏: /usr/games; 图形应用还有另外的地方)
可以将一些分散程序的符号链接放到/usr/local/bin中。

若对系统工具感兴趣(traceroute,ping,lsmod...),可以为路径加上sbin目录。
/usr/local/sbin
/usr/sbin
/sbin

帮助手册的路径: 建议不要修改。
传统的帮助手册路径来自环境变量MANPATH. /etc/manpath.config

4.2 提示符

PS1='[\u@\h \w]\n\A \!-\#\$ '

5. 主流shell的配置文件

files bash sh ksh zsh tcsh
/etc/.login         login
/etc/csh.login         login
~/.login         login
~/.logout         login
/etc/csh.cshrc         yes
~/.tcshrc ; ~/.cshrc         yes[a]
~/etc/ksh.kshrc     int.    
/etc/sh.shrc   int.[b]      
$ENV (typically ~/.kshrc) int.[e] int.[c][d] int.    
~/.bashrc int.+n/login        
~/.bash_profile login[g]        
~/.bash_login login[g]        
~/.bash_logout login        
~/.profile login[g] login login login[f]  
/etc/profile login login login login[f]  
/etc/zshenv       yes  
/etc/zprofile       login  
/etc/zlogin       login  
/etc/zlogout       login  
/etc/zshrc       int.  
~/.zshenv       yes  
~/.zprofile       login  
~/.zlogin       login  
~/.zshrc       int.  
n/login 表示如果shell不是登录shell,则读取文件。
login 表示如果shell是登录shell,则读取文件。
int. 表示如果shell是交互式的,则读取文件。
yes 表示shell在启动时始终读取文件。
" " 空白表示shell根本不读取文件。
[a] 仅在找不到~/.tcshrc时
[b] 仅限Bourne Shell的较新版本
[c] 适用于支持"用户可移植性实用程序"选项的系统; 变量的值必须是绝对路径,如果用户的真实有效用户ID或真实有效的组ID不同,则忽略它。
[d] $ENV是在Bourne Shell中的较新版本$HOME/.shrc
[e] 与 sh相同的行为,但仅在调用为 sh(bash 2+)或者自bash 4.2时,如果在POSIX兼容模式中显式调用(使用选项 --posix或 -o posix).
[f] a,b仅在sh/ksh兼容模式下(当调用为bash,sh,ksh时)
[g] 实际上是b,c,~/ .bash_profile的第一个可读,~/ .bash_login和~/ .profile ; 并且只有~/ .profile如果被调用为sh或者,至少在Bash 4.2中,如果在POSIX兼容模式中显式调用(带有选项--posix或-o posix)

6. 默认的bash

Bash主页是 http://www.gnu.org/software/bash/
https://wiki.archlinux.org/index.php/Bash
https://wiki.archlinux.org/index.php/Bash#Configuration_files

https://wiki.gentoo.org/wiki/Bash

6.1 手册

https://www.gnu.org/software/bash/manual/bash.html
file:///usr/share/doc/bash/bashref.html

6.2 bash启动文件

https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files

文件 描述 登录shell 交互,
非登录shell
/etc/profile 来源在应用程序设置/etc/profile.d/*.sh和/etc/bash.bashrc。 Yes No
~/.bash_profile 用户,之后/etc/profile。如果这个文件不存在,~/.bash_login并~/.profile按照此顺序检查。骨架文件/etc/skel/.bash_profile也来源~/.bashrc。 Yes No
~/.bash_logout 退出登录shell后。 Yes No
/etc/bash.bashrc 取决于-DSYS_BASHRC="/etc/bash.bashrc"编译标志。来源/usr/share/bash-completion/bash_completion。 No Yes
~/.bashrc 每用户,之后/etc/bash.bashrc。 No Yes

https://zhuanlan.zhihu.com/p/33833752
如何列出所有的 Bash Shell 内置命令

6.3 提示符

PS1='[\u@\h \w]\n\A \!-\#\$ '

PS1='\e[0;36m\][\u@\h \w]\e[0m\] \e[0;32m\]\n\A \!-\#\$\e[0m\] '
PS1='\e[0;36m\][\u@\h \w] \e[0;32m\]\n\A \!-\#\$\e[0m\] '

CodeColor
\e[0;30m\]Black
\e[0;31m\]Red
\e[0;32m\]Green
\e[0;33m\]Yellow
\e[0;34m\]Blue
\e[0;35m\]Magenta 品红
\e[0;36m\]Cyan 青色
\e[0;37m\]White
\e[0m\]Reset to standard colors 重置为标准色

7. 友好的fish

7.1 简介

https://en.wikipedia.org/wiki/Friendly_interactive_shell
https://zh.wikipedia.org/wiki/Fish
fish的设计目标是以易于发现,记忆和使用的方式为用户提供丰富的强大功能。
它的语法既不来自Bourne shell(ksh,bash,zsh)也不是C shell(csh,tcsh)。
与以前的shell(默认情况下禁用某些功能以节省系统资源)不同,fish默认启用所有功能。

https://wiki.archlinux.org/index.php/Fish
https://wiki.archlinux.org/index.php/Fish_(简体中文)
fish被有意设计成不完全与POSIX兼容。
fish的作者们认为POSIX中存在一些缺陷和矛盾,并通过fish简化的或不同的语法解决这些问题。
因此,即使简单的POSIX兼容的脚本也可能需要较多的修改,甚至完全重写,才能在fish中运行。
https://wiki.archlinux.org/index.php/Fish#Setting_fish_as_interactive_shell_only
只把fish设为交互式shell

https://wiki.gentoo.org/wiki/Fish
fish是OS X,Linux和其他家族的智能且用户友好的命令行shell。
fish包含语法突出显示,自动提示类型和精美的选项卡完成等功能,无需配置。
Fish不是POSIX 1003.1兼容的shell。它不读取/etc/profile,/etc/profile.env或/etc/profile.d/*目录。
建议不要将fish设置为默认登录shell.
这里有其中一位鱼类开发者和Arch wiki建议的技巧。这使得fish shell能够继承bash环境(写入并应该由bash shell 执行)
详见: https://wiki.gentoo.org/wiki/Fish#.bashrc_safety_net

https://github.com/fish-shell/fish-shell

7.2 查看帮助文档

$ help
file:///usr/share/doc/fish/index.html#docs
与其他shell不同,这里直接打开web页面文档,更方便查看,还能使用网页翻译。与下方官网页面相同。
https://fishshell.com/docs/current/index.html

官网的教学及常见问题
https://fishshell.com/docs/current/tutorial.html
https://fishshell.com/docs/current/faq.html

7.3 fish的配置

$ fish_config
Web config started at 'file:///home/toma/.cache/fish/web_config-S2EKS6.html'. Hit enter to stop.
不需要编写脚本,不需要手动修改配置文件,使用 fish_config 命令打开网页即可。
比如: http://localhost:8000/6d9de3bf1bf313e974c9738471da505c/#/colors

  • colors 配色模式 (我选择了省电的黑色背景,彩色文字模式)
  • prompt 提示符号 (我选择了完整路径显示加时间,加换行模式)
  • functions 功能
  • variables 变量
  • history 历史 (这里可以看到所有已经使用过的历史命令,可以手动删除不需要的命令)
  • bindings 绑定
  • abbreviations 缩写

8. zsh

这个可以吧shell玩的很酷炫,有非常多的插件可以选择。
也要话时间适应研究,这里就直接跳过了。
网络上有非常多的相关文章可共参考。

shell-Startup-Files的更多相关文章

  1. System startup files

    System startup files When you log in, the shell defines your user environment after reading the init ...

  2. Update startup files更新安装文件

    The service request did not complete because access to the service configuration manager was not gra ...

  3. Linux环境变量设置

    修改环境变量PATH 最近为root添加一个环境变量发现sudo su进去没有变化所以总结了一下所有设置环境变量的方法: 查看PATH:echo $PATH 直接在命令行修改,就可以使用,但是只有在当 ...

  4. Ubuntu 12.04 安装MySQL

    本文地址:http://www.cnblogs.com/yhLinux/p/4012689.html 本文适合新手入门. 本文是对 Ubuntu 12.04 环境下安装 MySQL 的记录,通过这两天 ...

  5. 【ecos学习1】wmware运行redboot[方法一]--脚本实现配置

    背景: 远程服务器Ubuntu生成软盘镜像,通过Mac下wmware运行. 1- 环境及版本: uname -a 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 ...

  6. Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh

    Hyperpolyglot Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh grammar | quoting and escaping | charactersvar ...

  7. 设置Linux环境的欢迎登陆信息

    1.编辑/etc/profile文件添加如下内容: for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ &quo ...

  8. tmux手册中文翻译

    man tmux可以看到最详细的tmux介绍,本文翻译自tmux手册. tmux全名叫"terminal multiplexer",终端多路复用器. tmux的命令格式为: tmu ...

  9. module使用和设置

    Modules environmentDescription This is a system that allows you to easily change between different v ...

  10. 从LFS官方文档构建完整Linux系统

    从LFS官方文档构建完整Linux系统 http://www.cnblogs.com/sonofdark/p/4962609.html 这不是新手教程!!! Parallels Desktop (为防 ...

随机推荐

  1. 在一个不稳定的无效的ViewState净的应用问题。 Erratic Invalid Viewstate issue in a .NET application

    这似乎是很多人都经历了同样的IE8的问题.似乎发生的是,不知何故,IE8(在IE8的渲染模式和IE7兼容模式)将失去4096个字节的HTML文档中该数据缺失导致此异常(通常你看到这一scriptres ...

  2. 深入JAVA注解-Annotation(学习过程)

    JAVA注解-Annotation学习 本文目的:项目开发过程中遇到自定义注解,想要弄清楚其原理,但是自己的基础知识不足以支撑自己去探索此问题,所以先记录问题,然后补充基础知识,然后解决其问题.记录此 ...

  3. 栈结构Stack

    package seday12; import java.util.Deque; import java.util.LinkedList; /** * @author xingsir * 栈结构. 栈 ...

  4. DBCP 数据源获取连接

    Main package p1; import com.JdbcUtils; import org.apache.commons.dbcp.BasicDataSource; import org.ap ...

  5. [USACO 08MAR]土地购买

    Description 题库链接 给你 \(n\) 块不同大小的土地.你可分批购买这些土地,每一批价格为这一批中最大的长乘最大的宽.问你买下所有土地的花费最小为多少. \(1\leq n\leq 50 ...

  6. listenTo - backbone.js

    listenToobject.listenTo(other, event, callback) 让 object 监听 另一个(other)对象上的一个特定事件.不使用other.on(event, ...

  7. 设计模式课程 设计模式精讲 16-4 代理模式Coding-动态代理

    1 代码演练 1.1 动态代理 2 疑难解答 2.1 动态代理invoke怎么执行的? 2.2 感觉这块理解的不是很好,下边有时间再看看 1 代码演练 1.1 动态代理 重点: 重点关注动态代理类 测 ...

  8. exec函数的执行对用户ID的影响

    exec不会创建新进程,只是分析加载程序文件或者shell执行文件,替换父进程的代码段.数据段.栈段,一个进程可以执行多个exec来执行多个程序,但进程只有一个 父进程经常是waitpid,获取子进程 ...

  9. 哈希表,Java中的hashCode

    哈希表: 将我们所需的键通过哈希函数转换索引,然后存储在一个数组中. 哈希表是时间和空间之间的平衡,体现空间换时间的算法思想(联想到预加载,缓存等,有时候多存储,预处理缓存一些东西,带来时间复杂度的改 ...

  10. java程序中的经常出现的的异常处理课后总结

    一.JDK中常见的异常情况 1.常见异常总结图 2.java中异常分类 Throwable类有两个直接子类: (1)Exception:出现的问题是可以被捕获的 (2)Error:系统错误,通常由JV ...