shell之间的比较
来源:互联网 发布:餐厅叫号软件 编辑:程序博客网 时间:2024/06/06 09:39
Feature | C/TC | Bourne | Bash | Korn |
---|---|---|---|---|
Variables: | ||||
Assigning values to local variables | set x = 5 | x=5 | x=5 | x=5 |
Assigning variable attributes | declare or typeset | typeset | ||
Assigning values to environment variables | setenv NAME Bob | NAME='Bob'; export NAME | export NAME='Bob' | export NAME='Bob' |
Read-Only Variables: | ||||
Accessing variables | echo $NAME set var = net echo ${var}worknetwork | echo $NAME var=netecho ${var}worknetwork | echo $NAME var=netecho ${var}worknetwork | echo $NAME or print $NAME var=netprint ${var}worknetwork |
Number of characters | echo $%var (tcsh only) | N/A | ${#var} | ${#var} |
Special Variables: | ||||
PID of the process | $$ | $$ | $$ | $$ |
Exit status | $status, $? | $? | $? | $? |
Last background job | $! (tcsh only) | $! | $! | $! |
Arrays: | ||||
Assigning arrays | set x = ( a b c ) | N/A | y[0]='a'; y[2]='b'; y[2]='c' fruit=(apples pears peaches plums) | y[0]='a'; y[1]='b'; y[2]='c' set –A fruit apples pears plums |
Accessing array elements | echo $x[1] $x[2] | N/A | echo ${y[0]} ${y[1]} | print ${y[0]} ${y[1]} |
All elements | echo $x or $x[*] | N/A | echo ${y[*]}, ${fruit[0]} | print ${y[*]}, ${fruit[0]} |
No. of elements | echo $#x | N/A | echo $y{#[*]} | print ${#y[*]} |
Command Substitution: | ||||
Assigning output of command to variable | set d = `date` | d=`date` | d=$(date) or d=`date` | d=$(date) or d=`date` |
Accessing values | echo $d echo $d[1], $d[2], ...echo $#d | echo $d | echo $d | print $d |
Command Line Arguments (Positional Parameters): | ||||
Accessing | $argv[1], $argv[2] or $1, $2 ... | $1, $2 ... $9 | $1, $2, ... ${10} ... | $1, $2, ... ${10} ... |
Setting positional parameters | N/A | set a b c set `date`echo $1 $2 ... | set a b c set `date` or set $(date)echo $1 $2 ... | set a b c set `date` or set $(date)print $1 $2 ... |
No. of command line arguments | $#argv $# (tcsh) | $# | $# | $# |
No. of characters in $arg[number] | $%1, $%2, (tcsh) | N/A | N/A | N/A |
Metacharacters for Filename Expansion: | ||||
Matches for: | ||||
Single character | ? | ? | ? | ? |
Zero or more characters | * | * | * | * |
One character from a set | [abc] | [abc] | [abc] | [abc] |
One character from a range of characters in a set | [a–c] | [a–c] | [a-c] | [a–c] |
One character not in the set | N/A (csh) [^abc] (tcsh) | [!abc] | [!abc] | [!abc] |
? matches zero or one occurrences of any pattern in the parentheses. The vertical bar represents an OR condition; e.g., either 2 or 9. Matches abc21, abc91, or abc1. | abc?(2|9)1 | abc?(2|9)1 | ||
Filenames not matching a pattern | ^pattern (tcsh) | |||
I/O Redirection and Pipes: | ||||
Command output redirected to a file | cmd > file | cmd > file | cmd > file | cmd > file |
Command output redirected and appended to a file | cmd >> file | cmd >> file | cmd >> file | cmd >> file |
Command input redirected from a file | cmd < file | cmd < file | cmd < file | cmd < file |
Command errors redirected to a file | (cmd > /dev/tty)>&errors | cmd 2>errors | cmd 2> file | cmd 2> errors |
Output and errors redirected to a file | cmd >& file | cmd > file 2>&1 | cmd >& file or cmd &> file or cmd > file 2>&1 | cmd > file 2>&1 |
Assign output and ignore noclobber | cmd >| file | N/A | cmd >| file | cmd >| file |
here document | cmd << EOF inputEOF | cmd << EOF inputEOF | cmd << EOF inputEOF | cmd << EOF inputEOF |
Pipe output of one command to input of another command | cmd | cmd | cmd | cmd | cmd | cmd | cmd | cmd |
Pipe output and error to a command | cmd |& cmd | N/A | N/A | (See coprocesses) |
Coprocess | N/A | N/A | N/A | command |& |
Conditional statement | cmd && cmd cmd || cmd | cmd && cmd cmd || cmd | cmd && cmd cmd || cmd | cmd && cmd cmd || cmd |
Reading from the Keyboard: | ||||
Read a line of input and store into variable(s) | set var = $< set var = 'line' | read var read var1 var2... | read var read var1 var2...readread -p promptread -a arrayname | read var read var1 var2...readread var?"Enter value" |
Arithmetic: | ||||
Perform calculation | @ var = 5 + 1 | var=`expr 5 + 1` | (( var = 5 + 1 )) let var=5+1 | (( var = 5 + 1 )) let var=5+1 |
Tilde Expansion: | ||||
Represent home directory of user | ~username | N/A | ~username | ~username |
Represent home directory | ~ | N/A | ~ | ~ |
Represent present working directory | N/A | N/A | ~+ | ~+ |
Represent previous working directory | N/A | N/A | ~- | ~– |
Aliases: | ||||
Create an alias | alias m more | N/A | alias m=more | alias m=more |
List aliases | alias | alias, alias -p | alias, alias –t | |
Remove an alias | unalias m | N/A | unalias m | unalias m |
History: | ||||
Set history | set history = 25 | N/A | automatic or HISTSIZE=25 | automatic or HISTSIZE=25 |
Display numbered history list | history | history, fc -l | history, fc –l | |
Display portion of list selected by number | history 5 | history 5 | history 5 10 history –5 | |
Re-execute a command | !! (last command) !5 (5th command)!v (last command starting with v) | !! (last command) !5 (5th command)!v (last command starting with v) | r (last command) r5 (5th command) r v (last command starting with v) | |
Set interactive editor | N/A (csh) bindkey -v or bindkey -e (tcsh) | N/A | set -o vi set -o emacs | set -o vi set -o emacs |
Signals: | ||||
Command | onintr | trap | trap | trap |
Initialization Files: | ||||
Executed at login | .login | .profile | .bash_profile | .profile |
Executed every time the shell is invoked | .cshrc | N/A | BASH_ENV=.bashrc (or other filename) (bash 2.x) ENV=.bashrc | ENV=.kshrc (or other filename) |
Functions: | ||||
Define a function | N/A | fun() { commands; } | function fun { commands; } | function fun { commands; } |
Call a function | N/A | fun fun param1 param2 ... | fun fun param1 param2 ... | fun fun param1 param2 ... |
Programming Constructs: | ||||
if conditional | if ( expression ) then commands endifif { ( command ) } then commandsendif | if [ expression ] then commands fiif command then commandsfi | if [[ string expression ]] then commandsfiif (( numeric expression ))then commandsfi | if [[ string expression ]] then commandsfiif (( numeric expression ))then commandsfi |
if/else conditional | if ( expression ) then commandselse commandsendif | if command then commandselse ...fi | if command then commandselse ...fi | if command then commandselse ...fi |
if/else/elseif conditional | if (expression) then commandselse if (expression) then commands else commands endif | if command then commandselif commandthen commands else commands fi | if command then commandselif command then commandselse commandsfi | if command then commandselif command then commandselse commandsfi |
goto | goto label ...label: | N/A | N/A | N/A |
switch and case | switch ("$value") case pattern1: commands breakswcase pattern2: commands breaksw default: commands breakswendsw | case "$value" in pattern1) commands ;;pattern2) commands ;;*) commands ;;esac | case "$value" in pattern1) commands ;;pattern2) commands ;;*) commands ;;esac | case "$value" in pattern1) commands ;;pattern2) commands ;;*) commands ;;esac |
Loops: | ||||
while | while (expression) commandsend | while command do commanddone | while command do commanddone | while command do commandsdone |
for/foreach | foreach var (wordlist) commandsend | for var in wordlist do commandsdone | for var in wordlist do commandsdone | for var in wordlist do commandsdone |
until | N/A | until command do commandsdone | until command do commandsdone | until command do commandsdone |
repeat | repeat 3 "echo hello" hellohello hello | N/A | N/A | N/A |
select | N/A | N/A | PS3="Please select a menu item" select var in wordlistdo commandsdone |
- shell之间的比较
- shell之间的比较
- 对象之间的比较
- 模块化之间的比较
- shell 之间的相互调用
- 函数指针之间的比较
- 对象之间比较的特殊
- Maven Ant之间的比较
- 统计模型之间的比较
- 统计模型之间的比较
- 统计模型之间的比较
- 统计模型之间的比较
- string之间的拼接比较
- 统计模型之间的比较
- PHP字符串之间的比较
- 两个hashMap之间的比较
- 日期字符串之间的比较
- java 框架之间的比较
- AS3:传值 传引用
- makemenuconfig问题
- 如何做好自己的工作
- find命令使用
- 缩写c#3.0完全自学手册
- shell之间的比较
- 疯子的百科
- javascript实现流行的淡入淡出相册
- 第一次面试
- android学习方法
- 基于STL的KMP算法
- 政协常委会第十次会议举行专题分组讨论
- 使用Msp430的串口中断接收一包数据
- 安装 drupal 6.17 出错:Deprecated: Function ereg() is deprecated in .../drupal-6.17/includes/file.inc on line 926