出自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
csh,tcsh,bash,sh等shell的区别
如何恢复linux和windows服务器被误删除文件
服务器是企业和个人重要的存储设备之一,而数据是企业和个人的珍贵财富,一旦服务器出现故障,会导致数据丢失或者受损,对公司或个人造成巨大的损失。因此,服务器备份和恢复数据备受
Tomcat服务器如何配置ssl证书
目录 一:证书配置 二:Tomcat配置 http自动跳转 https 总结一:证书配置下载已签发的证书、选择 Tomcat 版本 进入 Tomcat 目录创建个 cert 文件夹 将下载好的 SSL证书压缩包里的
CentOS修改服务器登录密码的详细指南
目录 一、引言 二、基本概念 三、修改密码的步骤 3.1 登录到 CentOS 服务器 3.2 修改当前用户的密码 3.3 修改其他用户的密码 3.4 密码复杂性检查 四、解决密码复杂性
Nginx解决跨域访问的完整实例
目录 引言 1. Nginx简介 2. 跨域问题简介 3. 解决跨域问题的方法 步骤一:安装和配置Nginx 步骤二:测试跨域访问 结论 总结 引言在现代的Web开发中,跨域访问是一种常见的
linux查看服务端证书方式(keytool和openssl)
目录 方法 1:直接从服务器上抓取并查看证书 方法 2:通过 openssl 抓取并查看证书 方法 3:下载并查看证书文件 证书信息解析 总结 查看服务器端的证书时,可以通过导入服务器
Ubuntu设置静态IP地址的方法步骤(亲测有效)
目录 一、找到位于 /etc/netplan 的 netplan 目录 二、修改或创建配置文件 三、配置与本机相符的网络适配器 四、禁用DHCP 五、配置静态IP、子网掩码、网关 六、配置DNS服务
Ubuntu配置静态IP的两种方法
目录 方法一 第一步:查看当前主机网络信息 第二步:修改配置文件 进入配置文件夹 第三步:使配置生效且检查网络连接状况 方法二 第一步:查看当前主机网络信息 第二步:修改
在LINUX系统上使用rsync命令详解
目录 LINUX使用rsync命令 Rsync 命令语法 Rsync 命令选项 Rsync 命令 命令示例 Rsync命令的基本语法 使用 Rsync 命令传输文件和目录 使用 Rsync 命令镜像数据
Linux系统中如何将普通用户权限提升至root权限
目录 首先重来就没有设置过ROOT用户 1.使用普通用户登录后输入以下命 2.设置root用户密码 3.输入“su”切换为root用户登录 4.输入“Visudo”命令
Linux解决Unknown filesystem问题
目录 Linux解决「Unknown filesystem」 遇到这种情况应该如何修复 总结Linux解决「Unknown filesystem」不知道大家在使用 Linux 系统的时候有没有遇见过 「Unknown filesys
nginx部署前端dist包详细图文教程
目录 下载nginx 配置 启动 总结 下载nginx下载地址https://nginx.org/en/download.htmldownload > Stable version 可选择稳定版的nginxnginx压缩包解压后的目录配置1.将打
VScode连接远程服务器踩坑实战记录(新版离线vscode-server安装)
目录 1、VScode扩展安装与配置 (1)vscode扩展安装 (2)vscode远程配置 2、vscode-server离线下载 (1)Commit ID查看 (2)安装包下载 3、文件解压缩 4、移动文件到指定位置
Linux系统中检查系统重启记录方案
目录 Linux中监控系统重启的重要性 深入探究:Linux 重启日志 使用last命令 uptime 命令 利用journalctl获取重启历史记录 who -b 命令 总结借其强大的架构和无与伦比的灵活性
LINUX中关于mkdir命令语法和实例解读
目录 MKDIR 命令的语法 mkdir 命令可用的选项 深入了解 MKDIR 命令示例 使用 mkdir 创建简单目录 在以其绝对功能和灵活性而闻名的 Linux 操作系统的动态世界中,有大量
Nginx 只允许 www 域名访问并禁止裸域名访问的实现步骤
目录 如何通过 Nginx 只允许 www 域名访问并禁止裸域名访问 步骤 1:配置 Nginx 处理 www 域名 步骤 2:禁止裸域名访问 步骤 3:重定向裸域名到 www 域名(可选) 步骤 4:重启 Ng
Nginx设置目录的访问权限实现访问静态资源
从日志信息来看,确实是权限问题(Permission denied)。我们可以重新检查并设置权限,确保 Nginx 用户有权限访问这些文件。检查 Nginx 用户:首先确认 Nginx 使用的用户,一般是 www-d
telnet Connection refused端口不通如何处理
目录 一、telnet简述 二、telnet Connection refused不通处理思路 一般对应上面的后两种情况 排查目的主机服务 总结 一、telnet简述telnet一般用于测试本机到目的主机
linux下图形界面和命令行界面的切换方式
目录 在linux下图形界面和命令行界面的切换 1. 图形界面和命令行界面的切换 2. 修改系统开机进入的界面 总结 在linux下图形界面和命令行界面的切换我估计好多喜欢用li
telnet nc命令返回“连接失败”问题及解决
目录 telnet nc命令返回“连接失败” 1、端口没有被监听 2、防火墙策略 3、目标主机不接受外部连接 总结 telnet nc命令返回“连接失败”当使用n
Linux无法为立即文档创建临时文件:设备上没有空间的问题解决
目录 1、问题描述 2、问题解决1、问题描述在命令行输入命令按Tab键时出现如下报错:很明显,设备上没有空间,即磁盘空间不足。通过命令查看具体情况如下:df -h2、问题解决首先想到
nginx配置history模式的使用小结
本文主要介绍了nginx配置history模式的使用小结,具体如下:worker_processes 1; events { worker_connections 1024;} http { include mime.types; default_t
Nginx获取客户端真实IP(real_ip_header)的实现
目录 一、配置 Nginx 获取客户端真实 IP 1、基本配置说明 2、set_real_ip_from详解 3、log_format 配置(参考) 二、调试与测试 三、Lua 中使用客户端真实 IP(参考) 四
Nginx配置WebSocket代理的示例代码
目录 官方文档代理样例 Linux 查看安装文件命令手册 Nginx 日志配置方案 成功解决问题–使用 Nginx 代理 WebSocket 可能出现的问题 Nginx 官方文档网址 nginx d
Linux系统下通过jar包进程号查询jar程序占用端口的常用方法
目录 方法1: 使用 netstat 命令 方法2: 使用 lsof 命令 方法3: 使用 ss 命令 方法4: 直接从Java进程读取 注意事项在Linux系统中,如果你已经知道了Java应用程序的进程ID(PID),你
linux日志轮询方案
目录 logrotate 简介 logrotate 配置文件 日志回滚原理 sshd 日志回滚实战 修改配置文件 重启rsyslog 强制切割 测试和运行 logrotate debug 模式 v
Linux自带的logrotate管理日志用法
目录 利用Linux自带的logrotate管理日志 1. logrotate简介 2. logrotate配置参数 3. nginx日志切割实例 4. 其他配置示例 总结 利用Linux自带的logrotate管理日志日
使用wget递归下载目录内容
是一种常见的命令行工具,用于从远程服务器下载整个目录及其子目录中的文件。它可以通过递归方式下载目录中的所有文件,并保持目录结构的完整性。wget是一个开源的非交互式命令
linux如何开启关闭防火墙
目录 linux开启关闭防火墙 1.关闭防火墙 2.设置开机不启动 3.查看防火墙状态 不同系统常见防火墙相关命令 下面是red hat/CentOs7关闭防火墙的命令 firewalld 总结
Nginx实现404页面的配置方法的两种方法
目录 第一种:Nginx自己的错误页面 第二种:反向代理的错误页面一个网站项目,肯定是避免不了404页面的,通常使用Nginx作为Web服务器时,有以下集中配置方式,一起来看看。第一种:Nginx
nginx出现500 Internal Server Error错误的解决方法
目录 问题原因 解决方法 1. 查看 Nginx 错误日志 2. 检查 Nginx 配置文件 3. 检查应用程序日志 4. 检查文件权限 5. 检查后端服务 示例 Nginx 配置检查步骤 检查步