您的位置:首页 > 运维架构 > Shell

Reference for shell scripting

2016-03-01 17:22 621 查看
${var} 和 $var的区别

http://stackoverflow.com/questions/8748831/when-do-we-need-curly-braces-in-variables-using-bash

正常情况下都可以,特殊情况下需要用花括号来区分变量名和其他的字符

“==”和 “=” 的区别

http://stackoverflow.com/questions/2600281/what-is-the-difference-between-operator-and-in-bash

正常情况下都可以使用,最好使用 “==”

[] 、 [[]] 、 test 、 ((number compare only)) 都可以用来判断条件

set / setenv / export /declare 的区别

export (in ksh/sh):exported var is accessible by all the shells or processes invoked by the original shell (an environment value)

set (in csh): set a local variable

setenv (in csh): set an environment variable

http://www.theunixschool.com/2010/04/what-is-difference-between-export-set.html

declare is used to declare variables and give them attribute

boolean expressions

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

[ -a File ]

[ -d dir ]

[ -z String ]

[ -n String ]

[ Integer1 OP Interger2 ] "OP" is one of -eq, -ne, -lt, -le, -gt or -ge

test exit status:

[ $? -eq 0 ]

Regular expressions may also be used in comparisons:

if [[ "$gender" == f* ]]

shell expansion

http://ss64.com/bash/syntax-expand.html

Arithmatic Operation

http://www.tldp.org/LDP/abs/html/arithexp.html

z=$((z+3))

let z=z+3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: