How to echo all the values ​​from an array in bash

I am using a bash script dialog. My script makes the difference between the files in two tar.gz. Each file is added to the array, and each delete file is placed in a different array.

All files are added to my two arrays, and when I want to echo them, it works

echo ${tabAjout[@]} echo ${tabSuppr[@]} 

Output:

 bonjour.txt.gpg test2.txt.gpg test.txt.gpg hello.txt.gpg 

Now I want to add this to msgbox.

 function affiche_message(){ #Personnalisation de la fenêtre $DIALOG --title "$1" \ --msgbox "$2" 20 45 } 

Call Function:

 affiche_message "Title" "Delete : ${tabSuppr[@]} \n\n Add : ${tabAjout[@]}" 

When I run my script, msgbox contains only the first values ​​of the array. If I change $ {tabAjout [@]} to $ {# tabAjout [@]}, the dialogs will display an echo that the array contains 3 values.

+6
source share
1 answer

Use * as an index to expand the array as a single word:

 "${tabSuppr[*]}" 

See man bash for clarification.

+17
source

Source: https://habr.com/ru/post/1013160/


All Articles