Markdown的使用转
:http://www.jianshu.com/p/617b59b36b85
1. Shell变量替换
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> **var="This is a line of text"**
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> **echo ${var/line/REPLACED}**
This is a REPLACED of text
2. 数据与关联数组的使用
2.1 数组的定义与使用
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> print ${a[*]}
1 2 3
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/>print ${a[@]}
1 2 3
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> b['id']='5'
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> print ${b['id']}
5
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> print ${#a[*]}
3
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/>fruits_value=([apple]='100dollars' [orange]='150 dollars')
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo "Apple costs ${fruits_value[apple]}"
Apple costs 100dollars
3. getReportData.sh
#!/usr/bin/bash
if [ $# != 0 ] && [ "$1" != "default" ]; then
echo -n "$1"
exit 0
fi
#week number
week_number=$(date +%w)
if [ $week_number -le 4 ]; then
interval=$(( -1*($week_number+4) ))
else
interval=$(( -1*($week_number-3) ))
fi
echo -n $(date -d "$interval day" +%Y%m%d)
exit 0
4. 表格的使用
怪木西西 | 怪木南南` | 怪木北北 |
---|---|---|
怪木中中 | 怪木发财 | 怪木白板 |
爱抽烟 | 爱喝茶 | 爱女人 test |
5. Shell变量的分片
假设我们有一个变量是:
var='http://www.baidu.com/data'
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${var%/*}
http://www.baidu.com
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${var%%/*}
http:
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${var#.*/}
http://www.baidu.com/data
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${var#*/}
/www.baidu.com/data
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${var##*/}
data
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${var/baidu/sina}
http://www.sina.com/data
@zdsuateng02:/gsa/bejgsa/home/c/h/chujq/> echo ${#var}
25
网友评论