簡體   English   中英

將 arrays 傳遞給 bash 腳本中的 function

[英]Passing arrays in to the function in bash script

我是 bash 腳本和編寫 bash 腳本的新手。 我已經聲明了一個數組並給出了值。 但是當我在循環中傳遞數組時,值並沒有進入循環。 下面是我的代碼

 declare -a files=( "A1S0" "D1S0" "D2S0" "D3S0" "D4S0" "D5S0" "D6S0" )   

     command_to_get_filesizes() {


        for i in ${#files[@]}; do
         echo test
        echo "${files[@]}"
        echo files[$i]

        echo  $(date +%m)
        aws s3api list-objects --bucket ui-dl-weather-ecmwf-ltf --prefix daily/ --query "Contents[?contains(Key, 'files[$i]$(date +%m%d)')]" --output text | awk '{print $2, $4}' >> "$FILESIZE"
        }
  command_to_get_filesizes()

你能幫我解決這個問題'files[$i]$(date +%m%d)'數組值應該出現在這個地方

eg: 'A1S0[$i]$(date +%m%d)'

語法錯誤。 #在那里做什么? 正確的是

 for i in "${files[@]}"; do

    echo Processing file $i
    .... 
    aws s3api list-objects --bucket ui-dl-weather-ecmwf-ltf --prefix daily/ --query "Contents[?contains(Key, '$i$(date +%m%d)')]" --output text | awk '{print $2, $4}' >> "$FILESIZE"

 done

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM