From cb6bbe95cd4901d43eb72e52b7cb8a89494b4d0b Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Wed, 13 Feb 2019 12:15:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=20bash=20=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=EF=BC=8C=E4=BB=A5=E5=8F=8A=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E4=BC=A0=E5=8F=82=E7=BB=99=E5=87=BD=E6=95=B0=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- languages/bash.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/languages/bash.sh b/languages/bash.sh index 5f56f6d..a2ff43b 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -1,6 +1,6 @@ ############################################################################## # BASH CHEATSHEET (中文速查表) - by skywind (created on 2018/02/14) -# Version: 44, Last Modified: 2018/10/17 03:15 +# Version: 45, Last Modified: 2019/02/13 12:15 # https://github.com/skywind3000/awesome-cheatsheets ############################################################################## @@ -296,6 +296,14 @@ IFS="/" array=($text) # 按斜杆分隔字符串 text 成数组,并赋值 text="${array[*]}" # 用空格链接数组并赋值给变量 text=$(IFS=/; echo "${array[*]}") # 用斜杠链接数组并赋值给变量 +A=( foo bar "a b c" 42 ) # 数组定义 +B=("${A[@]:1:2}") # 数组切片:B=( bar "a b c" ) +C=("${A[@]:1:2}") # 数组切片:C=( bar "a b c" 42 ) +echo "${B[@]}" # bar a b c +echo "${B[1]}" # a b c +echo "${C[@]}" # bar a b c 42 +echo "${C[@]: -2:2}" # a b c 42 减号前的空格是必须的 + $(UNIX command) # 运行命令,并将标准输出内容捕获并返回 varname=$(id -u user) # 将用户名为 user 的 uid 赋值给 varname 变量 @@ -338,6 +346,7 @@ function myfunc() { myfunc # 调用函数 myfunc myfunc arg1 arg2 arg3 # 带参数的函数调用 myfunc "$@" # 将所有参数传递给函数 +myfunc "${array[@]}" # 将一个数组当作多个参数传递给函数 shift # 参数左移 unset -f myfunc # 删除函数