(bash) adding suffix to each element of an array

This commit is contained in:
2026-04-13 09:21:45 +02:00
parent fc655cd6ad
commit d1749b61da
+6 -10
View File
@@ -1,15 +1,11 @@
#!/usr/bin/env bash
vector=({1..20})
array=("test0" "test1" "test2")
suffix="henlo"
echo "before : ${vector[@]}"
echo "${array[@]}"
echo ""
for n in ${!vector[@]}; do
echo $n
if (($n % 2 == 0)); then
unset vector[$n]
fi
done
array=("${array[@]/%/${suffix}}")
echo "after : ${vector[@]}"
echo "after_index : ${!vector[@]}"
echo "${array[@]}"