bash log

符号 $

var

$str表示变量,可赋值等操作,下面是一些特殊的变量
$# 是传给脚本的参数个数$0 是脚本本身的名字
$1 是传递给该shell脚本的第一个参数
$2 是传递给该shell脚本的第二个参数
$@ 是传给脚本的所有参数的列表
$* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过9个
$$ 是脚本运行的当前进程ID号
$? 是显示最后命令的退出状态,0表示没有错误,其他表示有错误

bracket

$(command) command substitution
${parameter} parameter expansing

$ animal=cat
$ echo $animals
                                # No such variable as “animals”.
$ echo ${animal}s
cats
$ echo $animal_food
                                # No such variable as “animal_food”.
$ echo ${animal}_food
cat_food

$ echo "$animal"s
cats

$ plural=s
$ echo $animal$plural
cats

Bracket

parentheses or “round brakets”

  • (( arithmetic operations
array=(1 2 3)
echo ${array[1]}
2

“sqaure brackets” or “box brackets”

test and [ builtins
[[ more functions. support && || =~(re)

braces or “curly brackets”

  • parameter expansion
  • truncate the contents
  • siimilar to sed
  • iterate
$ echo f{oo,ee,a}d
food feed fad

$ mv error.log{,.OLD}
(error.log is renamed to error.log.OLD because the brace expression
expands to "mv error.log error.log.OLD")

$ for num in {000..2}; do echo "$num"; done
000
001
002

$ echo {00..8..2}
00 02 04 06 08

$ echo {D..T..4}
D H L P T

“angle brakets”

> redirection
>> redirection at the end the orginal file

Various symbol

vertical bar

| refereed to as a “pipe”, direct output from the first command into the input for the second command
|| if the first command succeed the second will never be executed or opposite

&

& 同时执行多条命令,不管命令是否执行成功
&& 可同时执行多条命令,当碰到执行错误的命令时,将不再执行后面的命令。如果一直没有错误的,则执行完毕。

redirection

[HoWTO][http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html]

Referee

stackoverflow
shell中各种括号的作用
shell 编程基础
shell command example
BASH Programming

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值