返回顶部
首页 > 资讯 > 服务器 >csh,tcsh,bash,sh等shell的区别
  • 674
分享到

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

区别tcshcsh 2022-06-04 21:06:59 674人浏览 独家记忆
摘要

出自bash的faq,仔细看看。顺便翻译学习一下。 Section C: Differences from other Unix shellsC:跟其他UNIX shells脚本的区别C1) How doe

出自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

--结束END--

本文标题: csh,tcsh,bash,sh等shell的区别

本文链接: https://lsjlt.com/news/17916.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • csh,tcsh,bash,sh等shell的区别
    出自bash的faq,仔细看看。顺便翻译学习一下。 Section C: Differences from other Unix shellsC:跟其他UNIX shells脚本的区别C1) How doe...
    99+
    2022-06-04
    区别 tcsh csh
  • csh,tcsh,bash,sh等shell的区别是什么
    本篇内容主要讲解“csh,tcsh,bash,sh等shell的区别是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“csh,tcsh,bash,sh等shell的区别是什么”吧!出自bash...
    99+
    2023-06-09
  • Shell编程之/bin/bash和/bin/sh的区别浅析
    目录前言正题注意补充:docker容器使用/bin/bash命令总结前言 早期,学过shell的5种启动方式,学的没有那么深入。从而导致了想深究一下docker exec 命令为什么...
    99+
    2024-04-02
  • bash shell和dash shell的区别详解
    最近在工作中遇到一个很奇葩的问题,就是一个嵌入式的SDK编译,它里面执行shell命令的时候,使用的dash shell来解析,而通常我们默认用的是bash shell来解析;我按照bash shell那样照常编写脚本,...
    99+
    2023-05-06
    bash shell dash shell
  • Linux shell脚本开头#!/bin/bash和#!/bin/sh分析与区别是什么
    Linux shell脚本开头#!/bin/bash和#!/bin/sh分析与区别是什么,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。很多人都误以为Linux中shell脚...
    99+
    2023-06-28
  • ubuntu下source、sh、bash、./执行脚本的区别是什么
    这篇文章主要介绍“ubuntu下source、sh、bash、./执行脚本的区别是什么”,在日常操作中,相信很多人在ubuntu下source、sh、bash、./执行脚本的区别是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作...
    99+
    2023-06-13
  • ./ 和 sh 的区别是什么
    ./ 和 sh 的区别是什么?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。./ 和 sh的使用区别使用“./”执行脚本,对应的xxx.sh脚本必须要有执行权限;使用“sh”...
    99+
    2023-06-09
  • ./ 和 sh 的使用区别详解
    ./ 和 sh的使用区别 1、使用“./”执行脚本,对应的xxx.sh脚本必须要有执行权限; 2、使用“sh” 执行脚本,对应的xxjonIGekx.sh没有执行权限,亦可执行; 3、当脚本开头使用#!设置使...
    99+
    2022-06-04
    ./和sh的使用 ./和sh
  • 浅谈Linux 脚本 sh 和 ./ 的区别
    如果.不在PATH里面,要执行当前目录下的可执行文件,使用全路径: ./executable-file PATH是环境变量,如果将当前目录“./”添加到环境变量中,那么也可以不用“./”,直接输入当前目录下...
    99+
    2022-06-04
    浅谈 脚本 区别
  • Linux脚本中sh和 ./的区别是什么
    这篇文章主要为大家展示了“Linux脚本中sh和 ./的区别是什么”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux脚本中sh和 ./的区别是什么”这篇文章吧。如果.不在PATH里面,要执...
    99+
    2023-06-09
  • c语言中等于和等于等于的区别
    在 c 语言中,"等于"(=)用于赋值,而 "等于等于"(==)用于比较。等于(=)运算符:将右侧值赋值给左侧变量。等于等于(==)运算符:比较两个值是否相等,返回布尔值(true/fa...
    99+
    2024-05-02
    c语言
  • php中恒等与等于的区别是什么
    本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑php中恒等与等于的比较等式(==)运算等式(==)运算符是比较、并测试左边的变量(表达式或常量)是否与右边的变量(表达式或常量)具有相同的值;该运算符进行的比较是松散...
    99+
    2019-04-27
    php 恒等 等于 === ==
  • php中恒等与等于的区别有哪些
    这篇文章主要介绍“php中恒等与等于的区别有哪些”,在日常操作中,相信很多人在php中恒等与等于的区别有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”php中恒等与等于的区别有哪些”的疑惑有所帮助!接下来...
    99+
    2023-06-29
  • c语言中等于和双等于的区别
    c 语言中,“==”和“===”比较运算符的区别在于:“==”只比较值,而“===”同时比较值和类型。因此,使用“==”时不同类型的值可能相等,而使用“===”时只有值和类型都相等才返回...
    99+
    2024-04-27
    c语言
  • c语言中单等号和双等号的区别
    单等号 (=) 用于赋值,将右边值赋给左边变量;双等号 (==) 用于比较,判断两个操作数是否相等,返回 0(假)或 1(真)。 C 语言中单等号和双等号的区别 在 C 语言中,单等号...
    99+
    2024-05-02
    c语言
  • JavaScript中三等号和双等号的区别是什么
    这篇文章给大家分享的是有关JavaScript中三等号和双等号的区别是什么的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。三等号和双等号的区别// 双等号 - 将两个操作数转换为相同类...
    99+
    2023-06-27
  • 详解Shell $*和$@之间的区别
    $* 和 $@ 都表示传递给函数或脚本的所有参数,我们已在《Shell特殊变量》一节中进行了演示,本节重点说一下它们之间的区别。 当 $* 和 $@ 不被双引号" "包围时,它们之间没有任何区别,都是将接收到的每个参数看...
    99+
    2022-06-04
    Shell $* $@
  • 详谈python中subprocess shell=False与shell=True的区别
    shell=True参数会让subprocess.call接受字符串类型的变量作为命令,并调用shell去执行这个字符串,当shell=False是,subprocess.call只...
    99+
    2024-04-02
  • 您了解 ASP、Bash、Linux 和 NumPy 的区别吗?
    ASP、Bash、Linux 和 NumPy 都是计算机领域内常见的工具或技术。虽然它们各自有着不同的功能和应用场景,但是对于初学者来说,很容易混淆它们之间的区别。本文将会介绍这几个工具或技术的区别和应用场景,并且演示一些相关的代码。 一、...
    99+
    2023-09-09
    bash linux numpy
  • Shell中exit和return的区别讲解
    1.exit命令 exit命令是Shell内建命令,用于退出当前Shell进程。使用格式如下: exit [<n>] 可以指定退出状态n,n的取值范围是0-255,一般情况下,0表示正常退出,非零表示异...
    99+
    2022-06-04
    shell中exit和return shell中exit和return的区别讲解
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作