看图! shell 有 bourne shell和 c shell两大家族。
sh shell阶段:
标准化阶段,都向后兼容sh shell
On some Unix systems, the various shells are all installed under their own names. The sh program is different from kshor bash, and csh is different from tcsh. So if ,you want to use an old Bourne shell, you type sh; if you want to use Bash, you type bash. Similarly, you can use either csh(the standard C-Shell) or tcsh(the enhanced C-Shell).
On many systems, however, the newer shells have replaced the old ones, and you won’t find the Bourne shell or the C-Shell. Instead, if you type sh, you will get either Bash or the Korn shell; and if you type csh, you will get the Tcsh. –注:各种shell在系统上的叫法!(希望以后见到不要疑惑!)
SHELL NAME OF THE PROGRAM ------------- ----------------------------- Bash bash or sh Bourne Shell sh C-Shell csh FreeBSD Shell sh Korn Shell ksh or sh Pdksh ksh Tcsh tcsh or csh Zsh zsh–例如,本机的情况: a, # sh 的情况: 这里,sh 指向了 bash! –linux:
$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Oct 20 09:38 /bin/sh -> bashb,#ksh 的情况 linux-ksh 的指向:
$ ls -l /bin/ksh lrwxrwxrwx 1 root root 21 Nov 2 05:16 /bin/ksh -> /etc/alternatives/ksh $ ls -l /etc/alternatives/ksh lrwxrwxrwx 1 root root 10 Nov 2 05:16 /etc/alternatives/ksh -> /bin/ksh93最后还是指向了 ksh93,ksh93就是一个执行文件。
$ ls -l /bin/ksh93 -rwxr-xr-x 1 root root 1282980 Oct 2 04:54 /bin/ksh93使用Ksh时,非常重要的一点是判断当前版本究竟是兼容ksh88,还是ksh93标准规范, 为了判断这一点,我们需要查看ksh的版本。 进入到ksh命令行下,输入如下查询:
$ echo $KSH_VERSION` #(只有ksh有该变量.) Version AJM 93t+ 2010-02-02 或 @(#)PD KSH v5.2.14 99/07/13.2–解释: ①:pdksh(ksh的克隆,没有许可认证–>停止不前!) 在Redhat AS 4下,输出则是@(#)PD KSH v5.2.14 99/07/13.2, 这是一个public domain version,支持大多数88版的特性。 ②:Version JM 93t+ 2010-03-05 这是AT&T的官方版本,支持的是ksh93标准。 对于有些ksh93实现而言,并不支持变量$KSH_VERSION, 如果出现这种情况,可以用${.sh.version}来代替(这个变量则不被pdksh所支持)
如 本机 AIX-UNIX: $ echo ${.sh.version}` Version AJM 93t+ 2010-02-02获取ksh版本的脚本 脚本来自:http://ast-users.research.att.narkive.com/6hwolmZ1/get-print-which-ksh-version-i-am-running
# ksh88 based shells if [[ ${RANDOM} != ${RANDOM} ]]; then # well, bash too if [[ -n ${BASH_VERSION:-} ]]; then echo bash ${BASH_VERSION} # ksh93 $SECONDS contains a dot or a comma elif [[ ${SECONDS} = *[.,]* ]]; then echo ksh93 ${.sh.version} elif [[ -n ${KSH_VERSION:-} ]]; then echo pdksh ${KSH_VERSION} else echo ksh88 fi else echo some shell or syntax error bcoz of [[ ... ]] filinux&freebsd 使用文件 /etc/shells 注册了安装的所有shell程序, 但是商业系统可能并没有,如(AIX &solaris(SUNOS也没有) )! 在一些系统上,除非shell列举在了/etc/shells上,否则不允许使用chsh修改到该shell。
–1.先确认系统有哪几种 shell:
$ cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/zsh /bin/ksh–2. 临时体验其他的shell: (1)系统启动时,会启动一个shell,称为 登录shell (shell是一个程序,可以停止,也可启动其他shell). (2)命令less /etc/shells可以查看系统中的可用shell;
$SHELL 变量 :查看的是登陆shell全路径名称! echo $SHELL $0 变量 : 查看的是 当前 shell 名称! echo $0(3)如果想临时改变shell,只需要在登录shell中输入新shell对应的程序名即可: $ ksh 。
–3.永久改变shell: 永久改变登录shell: chsh(root及普通用户都可以使用chsh实现) 登录shell的信息保存在口令文件中:/etc/passwd , 直接修改这个文件,可能会破坏该文件,影响系统启动,所以建议使用命令chsh来修改! 使用命令: chsh [ -s shell ] [ userid ] 【chsh即change shell缩写】 # 这里,shell是绝对路径名 : /bin/bash
例子:将默认的登录shell改为tcsh: $ chsh –s /bin/tcsh注:默认改变是当前用户的登陆shell故不用写userid, 而且普通账户只能改变自己的启动shell. root(超级用户)可以改变其它账户的启动shell
–note: 一些系统并没有 chsh 命令,如AIX & solaris.
--AIX: $ passwd -s --solaris: $ passwd -e --最好使用: $ usermod -s