如何在bash中回显数组中的所有值 [英] How to echo all values from array in bash
问题描述
我正在使用对话框制作一个 bash 脚本.我的脚本使两个 tar.gz 中的文件有所不同.每个添加文件都放在一个数组中,每个删除文件都放在另一个数组中.
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[@]}
输出是:
bonjour.txt.gpg test2.txt.gpg test.txt.gpg
hello.txt.gpg
现在我想在 msgbox 中添加这个.
Now I want add this in msgbox.
function affiche_message(){
#Personnalisation de la fenêtre
$DIALOG --title "$1"
--msgbox "$2" 20 45
}
调用函数:
affiche_message "Title" "Delete : ${tabSuppr[@]}
Add : ${tabAjout[@]}"
当我运行我的脚本时,msgbox 只包含数组的第一个值.如果我将 ${tabAjout[@]} 更改为 ${#tabAjout[@]},对话框窗口会回显该数组包含 3 个值.
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.
推荐答案
使用*
作为下标,将数组展开为单个单词:
Use *
as the subscript to expand the array as a single word:
"${tabSuppr[*]}"
请参阅 man bash
了解说明.
这篇关于如何在bash中回显数组中的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!