删除一个字符串中后面的字符
$ str=foo_bar:baz
$ echo "${str%%:*}"
foo_bar
删除一个字符串前面的字符
$ str=foo_bar:baz
$ echo "${str##*:}"
baz
字符串转成 List
$ str=‘a|b|c’
$ arr=${str//|/ } && echo $arr
a b c
List 转成字符串
$ arr=(1 2 3)
$ str=$(printf "%s," ${arr[@]:0:2})
1,2
字符串替换
$ str=sh_c
$ echo ${str/_/-}
sh-c
List 数量
$ echo ${#arr[@]}
删除最后一个字符
$ str='123'
$ echo ${str::-1}
12
Map 操作
declare -A regions
regions=( ["SGP"]=40 ["NRT"]=25 )
regions["CDG"]=20
echo ${regions["SGP"]}
let a=5+4
echo $a # 9
let "a = 5 + 4"
echo $a # 9
let a++
echo $a # 10
let "a = 4 * 5"
echo $a # 20
let "a = $1 + 30"
echo $a # 30 + first command line argument
添加 $PREFIX 前缀
find nginx/app -type d -printf '$(PREFIX)/%p '
cat << EOF > all.txt
binance,"2018-09-01",6986,6312,988,61440.61093546052
binance,"2018-09-02",5644,4950,968,34594.98045481693
bitfinex,"2018-10-22",277,236,56,32873.3055055309,29650.881664956407
bitfinex,"2018-10-23",275,222,66,19275.46345581395,37960.79022311062,4431531.91919
EOF
## 根据第二行,再第一行排序,以 ',' 分割
sort -k 2,2 -k 1,1 -t , all.txt > all.csv
$ complete -F systemctl -r