Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在bash脚本中将数组传递给函数_Arrays_Bash_Syntax - Fatal编程技术网

Arrays 在bash脚本中将数组传递给函数

Arrays 在bash脚本中将数组传递给函数,arrays,bash,syntax,Arrays,Bash,Syntax,我不熟悉bash脚本和编写bash脚本。我声明了一个数组,并给出了值。 但是当我在循环中传递数组时,值不会进入循环。 下面是我的代码 declare -a files=( "A1S0" "D1S0" "D2S0" "D3S0" "D4S0" "D5S0" "D6S0" ) command_to_get_filesizes() { for i in ${#files[@]}; do echo test echo "${fil

我不熟悉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()
你能帮我做这个吗文件[$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

添加一个shebang,然后将脚本粘贴到那里:如上所述,我尝试过,但$i没有打印任何内容。。。你能帮我一下吗?$i正在打印数组中的1,2,3,4段值,而不是,你可以通过在bash命令行中尝试这段代码很容易看到:declare-a files=A1S0 D1S0 D2S0;对于${files[@]}中的i;不要重复$i;完成。确保真正复制和粘贴我写的东西。