csh,tcsh,bash,sh等shell的區(qū)別
更新時(shí)間:2014年02月27日 16:17:05 作者:
這篇文章主要介紹了linux下csh, tcsh,bash, sh等shell的區(qū)別?,需要的朋友可以參考下
出自bash的faq,仔細(xì)看看。順便翻譯學(xué)習(xí)一下。
復(fù)制代碼 代碼如下:
Section C: Differences from other Unix shells
C:跟其他UNIX shells腳本的區(qū)別
C1) How does bash differ from sh, the Bourne shell?
C1) bash和 sh、Bourne shell的區(qū)別
This is a non-comprehensive list of features that differentiate bash
from the SVR4.2 shell. The bash manual page explains these more
completely.
這時(shí)一個(gè)不全面的bash和SVR4.2 shell特性區(qū)別的列表,bash手冊(cè)解釋的更詳細(xì)
Things bash has that sh does not:
bash特有的功能:
long invocation options
長(zhǎng)選項(xiàng)的調(diào)用
[+-]O invocation option
-l invocation option
`!' reserved word to invert pipeline return value
!嘆號(hào)保留字對(duì)管道返回的值取反
`time' reserved word to time pipelines and shell builtins
time保留字測(cè)試管道或內(nèi)建命令耗時(shí)情況
the `function' reserved word
the `select' compound command and reserved word
select復(fù)合命令和保留字
arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
算術(shù)命令: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)形式的命令的替換,相當(dāng)于$(cat filename)
the ${#param} parameter value length operator
${#param} 測(cè)試參數(shù)param的值的長(zhǎng)度
the ${!param} indirect parameter expansion operator
${!param} 間接參數(shù)擴(kuò)展操作
the ${!param*} prefix expansion operator
${!param*} 前綴擴(kuò)展操作
the ${param:offset[]} parameter substring operator
${param:ffset[]}參數(shù)通過(guò)偏移量截取子串操作
the ${param/pat[/string]} parameter pattern substitution operator
${param/pat[/string]} 參數(shù)模式替換的操作
expansions to perform substring removal (${p%[%]w}, ${p#[#]w})
擴(kuò)展子串刪除命令:(${p%[%]w}, ${p#[#]w})
expansion of positional parameters beyond $9 with ${num}
擴(kuò)展了為止參數(shù)超過(guò)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
上邊一堆的環(huán)境變量
DEBUG trap
ERR trap
調(diào)試和錯(cuò)誤陷阱
variable arrays with new compound assignment syntax
數(shù)組和復(fù)合賦值運(yùn)算符的語(yǔ)法規(guī)則
redirections: <>, &>, >|, <<<, [n]<&word-, [n]>&word-
重定向規(guī)則: <>, &>, >|, <<<, [n]<&word-, [n]>&word-
prompt string special char translation and variable expansion
提示字符串特殊字符的轉(zhuǎn)化和變量展開(kāi)
auto-export of variables in initial environment
自動(dòng)繼承初始化的環(huán)境變量
command search finds functions before builtins
命令搜查函數(shù)限于內(nèi)建命令
bash return builtin will exit a file sourced with `.'
bash返回內(nèi)建命令 將退出一個(gè).文件源
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
上邊一堆內(nèi)建命令
bash reads ~/.bashrc for interactive shells, $ENV for non-interactive
bash reads這樣寫(xiě)交互腳本,環(huán)境變量非交互的。
bash restricted shell mode is more extensive
bash更廣泛的受限模式
bash allows functions and variables with the same name
允許函數(shù)名變量名一樣
brace expansion
括號(hào)擴(kuò)展
tilde expansion
~波浪號(hào)擴(kuò)展
arithmetic expansion with $((...)) and `let' builtin
算術(shù)擴(kuò)展:$((...)) 和let命令
the `...' extended conditional command
`...` 命令擴(kuò)展
process substitution
進(jìn)程替換
aliases and alias/unalias builtins
別名的內(nèi)建命令
local variables in functions and `local' builtin
函數(shù)內(nèi)本地變量
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內(nèi)建命令。
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風(fēng)格的通配符類、等價(jià)類、通配符號(hào)
egrep-like extended pattern matching operators
case-insensitive pattern matching and globbing
不區(qū)分大小寫(xiě)的模式匹配和通配符
variable assignments preceding commands affect only that command,
even for builtins and functions
變量賦值前的命令只影響那個(gè)命令,包括內(nèi)建命令和函數(shù)
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
調(diào)試支持,包括caller內(nèi)建命令和新變量
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:
執(zhí)行情況的不同:
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
相關(guān)文章
Shell實(shí)現(xiàn)判斷進(jìn)程是否存在并重新啟動(dòng)腳本分享
這篇文章主要介紹了Shell實(shí)現(xiàn)判斷進(jìn)程是否存在并重新啟動(dòng)腳本分享,本文給出了兩個(gè)實(shí)現(xiàn)腳本,分簡(jiǎn)潔版和詳細(xì)版,需要的朋友可以參考下2014-09-09Shell編程之/bin/bash和/bin/sh的區(qū)別淺析
在redhat的系統(tǒng)中,sh是一個(gè)到bash的軟鏈接,但是如果運(yùn)行如下程序會(huì)產(chǎn)生不一樣的結(jié)果,下面這篇文章主要給大家介紹了關(guān)于Shell編程之/bin/bash和/bin/sh的區(qū)別的相關(guān)資料,需要的朋友可以參考下2022-07-07Shell腳本實(shí)現(xiàn)亂序排列文件內(nèi)容的多種方法(洗牌問(wèn)題)
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)亂序排列文件內(nèi)容的多種方法(洗牌問(wèn)題),本文給出3個(gè)Shell腳本和一個(gè)Python腳本解決亂序排列文件內(nèi)容問(wèn)題,需要的朋友可以參考下2015-01-01一天一個(gè)shell命令 文本操作系列-comm命令用法
這篇文章主要介紹了linux系統(tǒng)下的comm命令是一個(gè)非常實(shí)用的文件對(duì)比命令,需要的朋友可以參考下2016-05-05linux下shell腳本備份文件的方法實(shí)現(xiàn)
本文主要介紹了linux下shell腳本備份文件的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08非常實(shí)用的23個(gè)Shell腳本實(shí)例
為大家整理了23個(gè)實(shí)例,通過(guò)23個(gè)實(shí)戰(zhàn)經(jīng)典腳本實(shí)例,可以拿來(lái)就用,根據(jù)大家的需求可以直接使用,為大家整理了23個(gè)實(shí)例,希望此文章對(duì)各位有所幫助2021-06-06