Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to echo all values from array in bash

I am making a bash script using dialog. My script make the difference between files in two tar.gz. Each add files are put in an array and each delete files are put in an other array.

All files are add in my two array and when I want echo them it's works

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

The output is :

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

Now I want add this in 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 the msgbox contains only the first values of the array. If I change ${tabAjout[@]} by ${#tabAjout[@]} the dialog windows echo that array contains 3 values.

like image 950
Mattasse Avatar asked Dec 14 '16 19:12

Mattasse


People also ask

How do you echo all elements in an array?

<? php $colors = array("Red", "Green", "Blue", "Yellow", "Orange"); // Loop through colors array foreach($colors as $value){ echo $value . "<br>"; } ?>

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script.

What does %% mean in bash?

So as far as I can tell, %% doesn't have any special meaning in a bash function name. It would be just like using XX instead. This is despite the definition of a name in the manpage: name A word consisting only of alphanumeric characters and under- scores, and beginning with an alphabetic character or an under- score.


1 Answers

Use * as the subscript to expand the array as a single word:

"${tabSuppr[*]}" 

See man bash for explanation.

like image 140
choroba Avatar answered Sep 22 '22 15:09

choroba