Skip to main content

Unconventional approach (all not pure bash):

  • if all elements in an array are just one characters (like in the question) you can use rev:

     echo "${array[@]}" | rev
    
  • otherwise if none of the array elements contain a new line:

     printf '%s\n' "${array[@]}" | tac | tr '\n' ' '; echo
    
  • and if you can use zsh:

     echo ${(Oa)array}
    

Unconventional approach (all not pure bash):

  • if all elements in an array are just one characters (like in the question) you can use rev:

     echo "${array[@]}" | rev
    
  • otherwise:

     printf '%s\n' "${array[@]}" | tac | tr '\n' ' '; echo
    
  • and if you can use zsh:

     echo ${(Oa)array}
    

Unconventional approach (all not pure bash):

  • if all elements in an array are just one characters (like in the question) you can use rev:

     echo "${array[@]}" | rev
    
  • otherwise if none of the array elements contain a new line:

     printf '%s\n' "${array[@]}" | tac | tr '\n' ' '; echo
    
  • and if you can use zsh:

     echo ${(Oa)array}
    
Source Link
jimmij
  • 48.7k
  • 20
  • 136
  • 141

Unconventional approach (all not pure bash):

  • if all elements in an array are just one characters (like in the question) you can use rev:

     echo "${array[@]}" | rev
    
  • otherwise:

     printf '%s\n' "${array[@]}" | tac | tr '\n' ' '; echo
    
  • and if you can use zsh:

     echo ${(Oa)array}