Concatenate an array with itself

Sort by

recency

|

146 Discussions

|

  • + 0 comments

    cat | xargs | awk '{print 0, $0}'

    easy

  • + 0 comments
    declare -a aray=()
    
    while IFS= read -r line || [ -n "$line" ]; do
        aray=("${aray[@]}" "$line")
    done
    
    doublearray=(${aray[@]} ${aray[@]} ${aray[@]})
    
    echo ${doublearray[@]}
    
  • + 0 comments
    • readarray -t arr
    • transarr=("{arr[@]}" "{transarr[@]}"
  • + 0 comments
    xargs yes 2>/dev/null | head -n 3 | tr $'\n' ' '
    

    Nifty trick

  • + 0 comments

    "Concatenating an array with itself creates a new array with the elements of the original array repeated twice in sequence." lotusbook247.com login