Questions tagged [bash-array]
The bash-array tag has no summary.
83 questions
7 votes
1 answer
363 views
Cannot delete bash associative array element
Consider an associative array in bash (versions 5.2.15(1)-release and 5.2.21(1)-release): declare -A ufs=(); ufs["one"]=1; ufs["two"]=2; ufs["three"]=3 printf '> %s\n' ...
2 votes
1 answer
430 views
How can I take a sub-array in bash of the first N elements of a string array with elements containing spaces?
This question is similar to this one but it differs from it: Consider this array with string elements which may contain spaces: a@W:$ arr=("eins" "zwei" "eins plus zwei" &...
0 votes
4 answers
263 views
bash - slice quoted substrings delimited by spaces into array
following example: string=" 'f o o' 'f oo' 'fo o' " array=($string) echo "${array[0]}" outputs: 'f while the expected output is: 'f o o' The only solution I came with is by ...
2 votes
1 answer
325 views
Why does printing an array with @ using printf in bash only print the first element?
I have an array snapshots=(1 2 3 4) When I run printf "${snapshots[*]}\n" It prints as expected 1 2 3 4 But when I run printf "${snapshots[@]}\n" It just prints 1 without a ...
3 votes
2 answers
2k views
How to extract and delete contents of a zip archive simultaneously?
I want to download and extract a large zip archive (>180 GB) containing multiple small files of a single file format onto an SSD, but I don't have enough storage for both the zip archive and the ...
3 votes
4 answers
3k views
How do I select an array to loop through from an array of arrays?
#!/usr/bin/bash ARGENT=("Nous devons économiser de l'argent." "Je dois économiser de l'argent.") BIENETRE=("Comment vas-tu?" "Tout va bien ?") aoarrs=("${...
1 vote
1 answer
1k views
Creating and appending to an array, mapfile vs arr+=(input) same thing or am I missing something?
Is there a case where mapfile has benefits over arr+=(input)? Simple examples mapfile array name, arr: mkdir {1,2,3} mapfile -t arr < <(ls) declare -p arr output: declare -a arr=([0])="1&...
1 vote
3 answers
4k views
Bash: converting a string with both spaces and quotes to an array
I have a function (not created by me) that outputs a series of strings inside of quotes: command <args> “Foo” “FooBar” “Foo Bar” “FooBar/Foo Bar” When I try to assign it to an array (Bash; BSD/...