Shell数组和字典总结

Shell数组和字典总结,第1张

names=()

names=("Bob" "Peter" "$USER" "Big Bad John")

names=([0]="Bob" [1]="Peter" [20]="$USER" [21]="Big Bad John")

names[0]="Bob"

photos=(~/"My Photos"/jpg)

files=()

declare -a myfiles='([0]="/home/a/bashrc" [1]="billing codesxlsx" [2]="helloc")'

declare -p myfiles

printf '%s\n' "${myfiles[@]}"

bash里面的字典叫做关联数组,字典其实和数组类似,不同点在于,字典的key是字符串,并且遍历时是随机的。

注意事项:

#!/bin/bash
func()
{
        START=$1
        END=$2
        awk -vstartt="$START" -vendt="$END" 'BEGIN{
                startm=mktime(gensub("-", " ", "g", startt) " 0 0 0")
                endtm=mktime(gensub("-", " ", "g", endt) " 0 0 0")
                for(i=startm;i<=endtm;i+=360024)
                        print strftime("%Y-%m-%d", i)
        }'
}
func "2013-10-1" "2013-10-5"


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13398652.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-28
下一篇 2023-07-28

发表评论

登录后才能评论

评论列表(0条)

保存