将 iitems 插入不同的数组

问题描述 投票:0回答:0

我想使用 bash 函数填充多个数组,并用标记指示下一个数组的插入(函数允许插入三个数组)。

我需要用户定义两个标记(可以由多字符序列组成)

multary ()
 {
  ## Insert items to multiple arrays.

  typeset -n _ary1="$1"
  typeset -n _ary2="$2"
  typeset -n _ary3="$3"

  _ary1=() _ary2=() _ary3=()

  while (( $# > 0 )); do
   parg="$1"
   case "$parg" in
     ("-m") marker="$2" ; shift 1 ;;
     ("--") shift 1 ; break ;;
     (*) break ;;
   esac
   shift 1
  done

  local ins_ary1=true
  local ins_ary2=false
  local ins_ary3=false

  for arg in "$@"; do
    if [[ "$arg" == "$ma" ]]; then
      ins_nomia=false
      ins_echenais=true
    elif [[ "$arg" == "$mb" ]]; then
      break
    elif [[ "$ins_ary2" == true ]]; then
      _ary2+=("$arg")
    elif [[ "$ins_ary3" == true ]]; then
      _ary3+=("$arg")
    fi
  done

 }

oeu oeu oeu oeu oeu oeu

arrays bash
© www.soinside.com 2019 - 2024. All rights reserved.