使用以下代码,如果管道到命令,我无法在 Bash 中克隆关联数组。我正在使用 Whiptail 显示进度条:
#!/bin/bash
declare -Ar ARR1=(
[a]='asdf'
[b]='qwerty'
[c]='yuio'
)
declare -A ARR2=()
clone() {
{
for key in "${!ARR1[@]}"; do
ARR2[$key]="${ARR1[$i]}"
echo "10" # Hardcoded percentage for Whiptail
done
} | whiptail --gauge "Cloning" 6 60 0
}
clone
for key in "${!ARR2[@]}"; do
echo "$key"
echo "${ARR2[$i]}"
done
卸下它的 Whiptail 管道:
#!/bin/bash
declare -Ar ARR1=(
[a]='asdf'
[b]='qwerty'
[c]='yuio'
)
declare -A ARR2=()
clone() {
{
for key in "${!ARR1[@]}"; do
ARR2[$key]="${ARR1[$i]}"
echo "10" # Hardcoded percentage for Whiptail
done
}
}
clone
for key in "${!ARR2[@]}"; do
echo "$key"
echo "${ARR2[$i]}"
done
有没有办法使用 Whiptail 管道进行这项工作?