打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
sh,bash,csh,tcsh等shell的区别
1.Introduction
Bourne Shell(即sh)是UNIX最初使用的shell,平且在每种UNIX上都可以使用。BourneShell在shell编程方便相当优秀,但在处理与用户的交互方便作得不如其他几种shell。
LinuxOS默认的是Bourne Again Shell,它是Bourne Shell的扩展,简称bash,与BourneShell完全兼容,并且在BourneShell的基础上增加,增强了很多特性。可以提供命令补全,命令编辑和命令历史等功能。它还包含了很多C Shell和KornShell中的优点,有灵活和强大的编辑接口,同时又很友好的用户界面

C Shell是一种比Bourne Shell更适合的变种Shell,它的语法与C语言很相似。Linux为喜欢使用CShell的人提供了Tcsh。
Tcsh是CShell的一个扩展版本。Tcsh包括命令行编辑,可编程单词补全,拼写校正,历史命令替换,作业控制和类似C语言的语法,他不仅和BashShell提示符兼容,而且还提供比Bash Shell更多的提示符参数。

Korn Shell集合了C Shell和Bourne Shell的优点并且和BourneShell完全兼容。Linux系统提供了pdksh(ksh的扩展),它支持人物控制,可以在命令行上挂起,后台执行,唤醒或终止程序。

Linux还包括了一些流行的Shell如:ash,zsh等。每个Shell都有它的用途,有些Shell是有专利的,有些能从Internet或其他来源获得。

2.How does bash differ from sh, the Bourne shell?
This is a non-comprehensive list of features thatdifferentiate bash from the SVR4.2 shell.  Thebash manual page explains these more completely.

Things bash has that sh does not:
       long invocation options
       [+-]O invocation option
       -l invocation option
       `!' reserved word to invert pipeline returnvalue
       `time' reserved word to time pipelines and shellbuiltins
       the `function' reserved word
       the `select' compound command and reservedword
       arithmetic for command: for ((expr1 ; expr2;expr3 )); do list; done
       new $'...' and $"..." quoting
       the $(...) form of command substitution
       the $(<filename) form of commandsubstitution, equivalent to
              $(cat filename)
       the ${#param} parameter value lengthoperator
       the ${!param} indirect parameter expansionoperator
       the ${!param*} prefix expansion operator
       the ${param:offset[]} parameter substringoperator
       the ${param/pat[/string]} parameter patternsubstitution operator
       expansions to perform substring removal(${p%[%]w}, ${p#[#]w})
       expansion of positional parameters beyond $9with ${num}
       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 assignmentsyntax
       redirections: <>,&>, >|,<<<,[n]<&word-,[n]>&word-
       prompt string special char translation andvariable expansion
       auto-export of variables in initialenvironment
       command search finds functions beforebuiltins
       bash return builtin will exit a file sourcedwith `.'
       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 -ooptname/s1 == s2/s1 < s2/s1 >s2/-nt/-ot/-ef/-O/-G/-S
       bash reads ~/.bashrc for interactive shells,$ENV for non-interactive
       bash restricted shell mode is moreextensive
       bash allows functions and variables with thesame name
       brace expansion
       tilde expansion
       arithmetic expansion with $((...)) and `let'builtin
       the `...' extended conditional command
       process substitution
       aliases and alias/unalias builtins
       local variables in functions and `local'builtin
       readline and command-line editing withprogrammable 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
       exported functions
       filename generation when using outputredirection (command >a*)
       POSIX.2-style globbing character classes
       POSIX.2-style globbing equivalence classes
       POSIX.2-style globbing collating symbols
       egrep-like extended pattern matchingoperators
       case-insensitive pattern matching andglobbing
       variable assignments preceding commands affectonly 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 andnew variables
       RETURN trap
Things sh has that bash does not:
       uses variable SHACCT to do shellaccounting
       includes `stop' builtin (bash can use aliasstop='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 shto create a subshell
       bash does not allow unbalanced quotes; shsilently inserts them at EOF
       bash does not mess with signal 11
       sh sets (euid, egid) to (uid, gid) if -p notsupplied and uid < 100
       bash splits only the results of expansions onIFS, using POSIX.2
              field splitting rules; shsplits all words on IFS
       sh does not allow MAILCHECK to be unset(?)
       sh does not allow traps on SIGALRM orSIGCHLD
       bash allows multiple option arguments wheninvoked (e.g. -x -v);
              sh allows only a singleoption argument (`sh -x -v' attempts
              to open a file named `-v',and, on SunOS 4.1.4, dumps core.
              On Solaris 2.4 and earlierversions, sh goes into an infinite
              loop.)
       sh exits a script if any builtin fails; bashexits only if one of
              the POSIX.2 `special'builtins fails

3.How does bash differ from the Korn shell, versionksh88?

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 thatlook like $PATH
       process substitution with named pipes if /dev/fdis not available
       the ${!param} indirect parameter expansionoperator
       the ${!param*} prefix expansion operator
       the ${param:offset[]} parameter substringoperator
       the ${param/pat[/string]} parameter patternsubstitution 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 andcommand substitution
       redirection: &>(stdout and stderr),<<<,[n]<&word-,[n]>&word-
       more extensive and extensible editing andprogrammable 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 -obraceexpand/-o histexpand/-o interactive-comments/
                -onotify/-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 matchingoperators
       case-insensitive pattern matching andglobbing
       `**' arithmetic operator to doexponentiation
       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 withoutdefinitions
       text of command history kept in a file, notmemory
       builtins: alias -x, cd old new, newgrp,print,
                read-p/-s/var?prompt, set -A/-o gmacs/
                -obgnice/-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 exportedvariables
       arithmetic evaluation done on arguments to somebuiltins
       reads .profile from $PWD when invoked as loginshell

Implementation differences:
       ksh runs last command of a pipeline in parentshell context
       bash has brace expansion by default (ksh88compile-time option)
       bash has fixed startup file for all interactiveshells; ksh reads $ENV
       bash has exported functions
       bash command search finds functions beforebuiltins
       bash waits for all commands in pipeline to exitbefore returning status
       emacs-mode editing has some slightly differentkey bindings


Which new features in ksh-93 are not in bash, and whichare?

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 associativearray
       `.' is allowed in variable names to create ahierarchical namespace
       more extensive compound assignment syntax
       discipline functions
       `sleep' and `getconf' builtins (bash hasloadable 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 listsfor 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 (combinationdup and close)
       for (( expr1; expr2; expr3 )) ; do list; done -arithmetic for command
       :, ++, --, `expr1 , expr2' arithmeticoperators
       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 itcompletes
       POSIX.2 `test'
       umask -S
       unalias -a
       command and arithmetic substitution performed onPS1, PS4, and ENV
       command name completion
       ENV processed only for interactive shells
       set -o pipefail

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
GNU bash实现机制与源代码简析
shell
crontab shell调用spark
Make Vim as Your Bash
Bash命令执行漏洞的详细分析
#!/bin/bash
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服