csh,tcsh,bash,sh等shell的区别

出自bash的faq,仔细看看。顺便翻译学习一下。

代码如下:

Section C: Differences from other Unix shells
C:跟其他UNIX shells脚本的区别
C1) How does bash differ from sh, the Bourne shell?
C1) bash和 sh、Bourne shell的区别
This is a non-comprehensive list of features that differentiate bash
from the SVR4.2 shell.  The bash manual page explains these more
completely.
这时一个不全面的bash和SVR4.2 shell特性区别的列表,bash手册解释的更详细
Things bash has that sh does not:
bash特有的功能:
        long invocation options
        长选项的调用
        [+-]O invocation option
        -l invocation option
        `!' reserved word to invert pipeline return value
         !叹号保留字对管道返回的值取反
        `time' reserved word to time pipelines and shell builtins
         time保留字测试管道或内建命令耗时情况
        the `function' reserved word
        the `select' compound command and reserved word
        select复合命令和保留字
        arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
        算术命令:for ((expr1 ; expr2; expr3 )); do list; done
        new $'...' and $"..." quoting
        新的引用方法$'...'  $"..."
        the $(...) form of command substitution
        $(...) 命令替代用法
        the $(<filename) form of command substitution, equivalent to
                $(cat filename)
        $(<filename)形式的命令的替换,相当于$(cat filename)
        the ${#param} parameter value length operator
        ${#param} 测试参数param的值的长度
        the ${!param} indirect parameter expansion operator
        ${!param} 间接参数扩展操作
        the ${!param*} prefix expansion operator
        ${!param*} 前缀扩展操作
        the ${param:offset[]} parameter substring operator
       ${param:ffset[]}参数通过偏移量截取子串操作
        the ${param/pat[/string]} parameter pattern substitution operator
        ${param/pat[/string]} 参数模式替换的操作
        expansions to perform substring removal (${p%[%]w}, ${p#[#]w})
         扩展子串删除命令:(${p%[%]w}, ${p#[#]w})
        expansion of positional parameters beyond $9 with ${num}
        扩展了为止参数超过9的限制
        variables: BASH, BASH_VERSION, BASH_VERSINFO, UID, EUID, REPLY,
                   TIMEFORMAT, PPID, PWD, OLDPWD, SHLVL, RANDOM, SECONDS,
                   LINENO, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE, HOSTNAME,
                   ENV, PS3, PS4, DIRSTACK, PIPESTATUS, HISTSIZE, HISTFILE,
                   HISTFILESIZE, HISTCONTROL, HISTIGNORE, GLOBIGNORE, GROUPS,
                   PROMPT_COMMAND, FCEDIT, FIGNORE, IGNOREEOF, INPUTRC,
                   SHELLOPTS, OPTERR, HOSTFILE, TMOUT, FUNCNAME, histchars,
                   auto_resume
        上边一堆的环境变量
        DEBUG trap
        ERR trap
        调试和错误陷阱
        variable arrays with new compound assignment syntax
         数组和复合赋值运算符的语法规则
        redirections: <>, &>, >|, <<<, [n]<&word-, [n]>&word-
         重定向规则: <>, &>, >|, <<<, [n]<&word-, [n]>&word-
        prompt string special char translation and variable expansion
        提示字符串特殊字符的转化和变量展开
        auto-export of variables in initial environment
        自动继承初始化的环境变量
        command search finds functions before builtins
        命令搜查函数限于内建命令
        bash return builtin will exit a file sourced with `.'
        bash返回内建命令 将退出一个.文件源
        builtins: cd -/-L/-P, exec -l/-c/-a, echo -e/-E, hash -d/-l/-p/-t.
                  export -n/-f/-p/name=value, pwd -L/-P,
                  read -e/-p/-a/-t/-n/-d/-s/-u,
                  readonly -a/-f/name=value, trap -l, set +o,
                  set -b/-m/-o option/-h/-p/-B/-C/-H/-P,
                  unset -f/-v, ulimit -m/-p/-u,
                  type -a/-p/-t/-f/-P, suspend -f, kill -n,
                  test -o optname/s1 == s2/s1 < s2/s1 > s2/-nt/-ot/-ef/-O/-G/-S
        上边一堆内建命令
        bash reads ~/.bashrc for interactive shells, $ENV for non-interactive
        bash reads这样写交互脚本,环境变量非交互的。
        bash restricted shell mode is more extensive
        bash更广泛的受限模式
        bash allows functions and variables with the same name
        允许函数名变量名一样
        brace expansion
        括号扩展
        tilde expansion
        ~波浪号扩展
        arithmetic expansion with $((...)) and `let' builtin
        算术扩展:$((...)) 和let命令
        the `...' extended conditional command
        `...` 命令扩展
        process substitution
        进程替换
        aliases and alias/unalias builtins
        别名的内建命令
        local variables in functions and `local' builtin
        函数内本地变量
        readline and command-line editing with programmable completion
        读取行和命令行可以编程完成
        command history and history/fc builtins
         查看历史命令
        csh-like history expansion
        other new bash builtins: bind, command, compgen, complete, builtin,
                                 declare/typeset, dirs, enable, fc, help,
                                 history, logout, popd, pushd, disown, shopt,
                                 printf
         上边一堆新的bash内建命令。
        exported functions
        filename generation when using output redirection (command >a*)
        重定向输出文件名的生成
        POSIX.2-style globbing character classes
        POSIX.2-style globbing equivalence classes
        POSIX.2-style globbing collating symbols
        POSIX.2风格的通配符类、等价类、通配符号
        egrep-like extended pattern matching operators
        case-insensitive pattern matching and globbing
        不区分大小写的模式匹配和通配符
        variable assignments preceding commands affect only that command,
                even for builtins and functions
        变量赋值前的命令只影响那个命令,包括内建命令和函数
        posix mode
        redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr,
                /dev/tcp/host/port, /dev/udp/host/port
        debugger support, including `caller' builtin and new variables
        调试支持,包括caller内建命令和新变量
        RETURN trap

Things sh has that bash does not:
下边是sh有但是bash木有的
        uses variable SHACCT to do shell accounting
        includes `stop' builtin (bash can use alias stop='kill -s STOP')
        `newgrp' builtin
        turns on job control if called as `jsh'
        $TIMEOUT (like bash $TMOUT)
        `^' is a synonym for `|'
        new SVR4.2 sh builtins: mldmode, priv

Implementation differences:
执行情况的不同:
        redirection to/from compound commands causes sh to create a subshell
        bash does not allow unbalanced quotes; sh silently inserts them at EOF
        bash does not mess with signal 11
        sh sets (euid, egid) to (uid, gid) if -p not supplied and uid < 100
        bash splits only the results of expansions on IFS, using POSIX.2
                field splitting rules; sh splits all words on IFS
        sh does not allow MAILCHECK to be unset (?)
        sh does not allow traps on SIGALRM or SIGCHLD
        bash allows multiple option arguments when invoked (e.g. -x -v);
                sh allows only a single option argument (`sh -x -v' attempts
                to open a file named `-v', and, on SunOS 4.1.4, dumps core.
                On Solaris 2.4 and earlier versions, sh goes into an infinite
                loop.)
        sh exits a script if any builtin fails; bash exits only if one of
                the POSIX.2 `special' builtins fails

下边都和上边比较雷同了。。。大致浏览吧。
C2) How does bash differ from the Korn shell, version ksh88?

Things bash has or uses that ksh88 does not:
        long invocation options
        [-+]O invocation option
        -l invocation option
        `!' reserved word
        arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
        arithmetic in largest machine-supported size (intmax_t)
        posix mode and posix conformance
        command hashing
        tilde expansion for assignment statements that look like $PATH
        process substitution with named pipes if /dev/fd is not available
        the ${!param} indirect parameter expansion operator
        the ${!param*} prefix expansion operator
        the ${param:offset[]} parameter substring operator
        the ${param/pat[/string]} parameter pattern substitution operator
        variables: BASH, BASH_VERSION, BASH_VERSINFO, UID, EUID, SHLVL,
                   TIMEFORMAT, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE,
                   HISTFILESIZE, HISTIGNORE, HISTCONTROL, PROMPT_COMMAND,
                   IGNOREEOF, FIGNORE, INPUTRC, HOSTFILE, DIRSTACK,
                   PIPESTATUS, HOSTNAME, OPTERR, SHELLOPTS, GLOBIGNORE,
                   GROUPS, FUNCNAME, histchars, auto_resume
        prompt expansion with backslash escapes and command substitution
        redirection: &> (stdout and stderr), <<<, [n]<&word-, [n]>&word-
        more extensive and extensible editing and programmable completion
        builtins: bind, builtin, command, declare, dirs, echo -e/-E, enable,
                  exec -l/-c/-a, fc -s, export -n/-f/-p, hash, help, history,
                  jobs -x/-r/-s, kill -s/-n/-l, local, logout, popd, pushd,
                  read -e/-p/-a/-t/-n/-d/-s, readonly -a/-n/-f/-p,
                  set -o braceexpand/-o histexpand/-o interactive-comments/
                  -o notify/-o physical/-o posix/-o hashall/-o onecmd/
                  -h/-B/-C/-b/-H/-P, set +o, suspend, trap -l, type,
                  typeset -a/-F/-p, ulimit -u, umask -S, alias -p, shopt,
                  disown, printf, complete, compgen
        `!' csh-style history expansion
        POSIX.2-style globbing character classes
        POSIX.2-style globbing equivalence classes
        POSIX.2-style globbing collating symbols
        egrep-like extended pattern matching operators
        case-insensitive pattern matching and globbing
        `**' arithmetic operator to do exponentiation
        redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr
        arrays of unlimited size
        TMOUT is default timeout for `read' and `select'
        debugger support, including the `caller' builtin
        RETURN trap
        Timestamps in history entries
        {x..y} brace expansion

Things ksh88 has or uses that bash does not:
        tracked aliases (alias -t)
        variables: ERRNO, FPATH, EDITOR, VISUAL
        co-processes (|&, >&p, <&p)
        weirdly-scoped functions
        typeset +f to list all function names without definitions
        text of command history kept in a file, not memory
        builtins: alias -x, cd old new, newgrp, print,
                  read -p/-s/var?prompt, set -A/-o gmacs/
                  -o bgnice/-o markdirs/-o trackall/-o viraw/-s,
                  typeset -H/-L/-R/-Z/-A/-ft/-fu/-fx/-l/-u/-t, whence
        using environment to pass attributes of exported variables
        arithmetic evaluation done on arguments to some builtins
        reads .profile from $PWD when invoked as login shell

Implementation differences:
        ksh runs last command of a pipeline in parent shell context
        bash has brace expansion by default (ksh88 compile-time option)
        bash has fixed startup file for all interactive shells; ksh reads $ENV
        bash has exported functions
        bash command search finds functions before builtins
        bash waits for all commands in pipeline to exit before returning status
        emacs-mode editing has some slightly different key bindings

C3) Which new features in ksh-93 are not in bash, and which are?

New things in ksh-93 not in bash-3.0:
        associative arrays
        floating point arithmetic and variables
        math library functions
        ${!name[sub]} name of subscript for associative array
        `.' is allowed in variable names to create a hierarchical namespace
        more extensive compound assignment syntax
        discipline functions
        `sleep' and `getconf' builtins (bash has loadable versions)
        typeset -n and `nameref' variables
        KEYBD trap
        variables: .sh.edchar, .sh.edmode, .sh.edcol, .sh.edtext, .sh.version,
                   .sh.name, .sh.subscript, .sh.value, .sh.match, HISTEDIT
        backreferences in pattern matching (\N)
        `&' operator in pattern lists for matching
        print -f (bash uses printf)
        `fc' has been renamed to `hist'
        `.' can execute shell functions
        exit statuses between 0 and 255
        `+=' variable assignment operator
        FPATH and PATH mixing
        getopts -a
        -I invocation option
        printf %H, %P, %T, %Z modifiers, output base for %d
        lexical scoping for local variables in `ksh' functions
        no scoping for local variables in `POSIX' functions

New things in ksh-93 present in bash-3.0:
        [n]<&word- and [n]>&word- redirections (combination dup and close)
        for (( expr1; expr2; expr3 )) ; do list; done - arithmetic for command
        ?:, ++, --, `expr1 , expr2' arithmetic operators
        expansions: ${!param}, ${param:offset[]}, ${param/pat[/str]},
                    ${!param*}
        compound array assignment
        the `!' reserved word
        loadable builtins -- but ksh uses `builtin' while bash uses `enable'
        `command', `builtin', `disown' builtins
        new $'...' and $"..." quoting
        FIGNORE (but bash uses GLOBIGNORE), HISTCMD
        set -o notify/-C
        changes to kill builtin
        read -A (bash uses read -a)
        read -t/-d
        trap -p
        exec -c/-a
        `.' restores the positional parameters when it completes
        POSIX.2 `test'
        umask -S
        unalias -a
        command and arithmetic substitution performed on PS1, PS4, and ENV
        command name completion
        ENV processed only for interactive shells
        set -o pipefail

(0)

相关推荐

  • Bash Shell中Shift用法分享

    shift可以用来向左移动位置参数.Shell的名字 $0第一个参数 $1第二个参数 $2第n个参数 $n所有参数 $@ 或 $*参数个数 $# shift默认是shift 1以下边为例: 复制代码 代码如下: cat shift.sh#----------------------------输出文字-开始----------------------------#!/bin/bashuntil [ -z "$1" ]  # Until all parameters used updo 

  • bash shell命令行选项与修传入参数处理

    在编写shell程序时经常需要处理命令行参数,本文描述在bash下的命令行处理方式.选项与参数:如下命令行:   复制代码 代码如下: ./test.sh -f config.conf -v --prefix=/home -f为选项,它需要一个参数,即config.conf, -v 也是一个选项,但它不需要参数.--prefix我们称之为一个长选项,即选项本身多于一个字符,它也需要一个参数,用等号连接,当然等号不是必须的,/home可以直接写在--prefix后面,即--prefix/home,

  • Shell 编程:Bash空格的那点事

    先了解下bash中什么时候该用空格,什么时候不该用. 1. 等号赋值两边不能有空格 2. 命令与选项之间需要空格 3. 管道两边空格可有可无 我们来看看常见的问题 1. 赋值时等号两边或者只有左边多了空格 igi@gentoo ~ $ var1 = test bash: var1: command not found igi@gentoo ~ $ echo ${var1:?error} bash: var1: error igi@gentoo ~ $ echo ${var1?error} bas

  • shell(bash)下“time” 命令的输出详解

    前言 相信大家都知道bash下time是一个很有用的命令,它可以为一段脚本或一个程序的执行计时,这通常在粗略比较程序执行效率的时候很方便.但是你会发现,time命令输出的时间文字不能被简单地重定向,例如重定向至一个文本文件,只能显示在屏幕上,这对于非交互计时很不方便. 例如: $ time find . -name "mysql.sh" >1.txt real 0m0.081s user 0m0.060s sys 0m0.020s $ time find . -name &quo

  • 让代码整洁、过程清晰的BASH Shell编程技巧

    这是我写BASH程序的招式.这里本没有什么新的内容,但是从我的经验来看,人们爱滥用BASH.他们忽略了计算机科学,而从他们的程序中创造的是"大泥球"(译注:指架构不清晰的软件系统). 在此我告诉你方法,以保护你的程序免于障碍,并保持代码的整洁. 一.不可改变的全局变量 1.尽量少用全局变量 2.以大写命名 3.只读声明 4.用全局变量来代替隐晦的$0,$1等 在我的程序中常使用的全局变量: 复制代码 代码如下: readonly PROGNAME=$(basename $0) read

  • Bash Shell中忽略大小写的设置方法

    大多数人在使用 Bash 时,都会对其进行改造,因为默认的设置真的好难用- 参考以下 ~/.inputrc 设置: 复制代码 代码如下: # do not show hidden files in the list set match-hidden-files off   # auto complete ignoring case set show-all-if-ambiguous on set completion-ignore-case on "\ep": history-sear

  • 使用bash shell删除目录中的特定文件的3种方法

    我是一名Linux新用户.现在我需要清理一个下载目录中的文件,其实我就是想从-/Download/文件夹删去除了以下格式的文件外所以其它文件: 1.*.iso - 所有的iso格式的文件. 2.*.zip - 所有zip格式的文件. 我如何在一个基于Linux,OS X 或者 Unix-like 系统上的bash shell中删除特定的文件呢? Bash shell 支持丰富的文件模式匹配符例如: 1.* - 匹配所有的文件. 2.? - 匹配文件名中的单个字母. 3.[...] - 匹配封闭括

  • Bash Shell字符串操作小结

    1. 取长度 复制代码 代码如下: str="abcd"expr length $str   # 4echo ${#str}       # 4expr "$str" : ".*" # 4 好像一般使用第二种2. 查找子串的位置 复制代码 代码如下: str="abc"expr index $str "a"  # 1expr index $str "b"  # 2expr index $

  • linux BASH shell下设置字体及背景颜色

    BASH shell下设置字体及背景颜色 echo -e "\e[31mtest\e[41m" \e[30m 将字符的显示颜色改为黑色 \e[31m 将字符的显示颜色改为红色 \e[32m 将字符的显示颜色改为绿色 \e[33m 将字符的显示颜色改为淡红色 \e[34m 将字符的显示颜色改为蓝色 \e[35m 将字符的显示颜色改为紫色 \e[36m 将字符的显示颜色改为淡蓝色 \e[37m 将字符的显示颜色改为灰色 \e[40m -- \e[47m 设置背景色 \e[40m 将背景色设

  • Bash Shell 注释多行的几种方法

    1.最简单方法 复制代码 代码如下: :<<BLOCK ....注释内容 BLOCK 把输入重定义到前面的命令,但是 : 是空命令,所以就相当于注释了. 如果注释中有反引号的命令就会报错,反引号部分不会被注释掉,例如 var=`ls -l` 就不会被注释掉. 2.解决注释中有反引号的问题 A.方法一 复制代码 代码如下: :<<BLOCK' ....注释内容 'BLOCK B.方法二 复制代码 代码如下: :<<'BLOCK ....注释内容 BLOCK' C.方法三

随机推荐