Questions tagged [array]
A array is the simplest data-structure for storing items in continuously memory
641 questions
0 votes
0 answers
75 views
zsh associative array value data types
In ZSH, how do you set the value of an associative array parameter to an array? e.g., % declare -A a=() % a[first]=(1 2) zsh: a: attempt to set slice of associative array And when I try and append ...
1 vote
1 answer
110 views
What's the difference in manipulating the array between echo and printf in Bash?
I'm surprised by the difference in manipulating the array between echo and printf in Bash: printf cannot handle += operator Both printf and echo cannot get results of += out of while loop So, why? I'...
0 votes
3 answers
129 views
Making each word in a text file an item in a bash array
I have a string of text and spaces which looks like this: macOS windows arch-linux ubuntu_linux I want to append each item (with whitespace denoting a break between items) to a bash array. How do I ...
4 votes
1 answer
156 views
How to split output of a shell command on spaces while taking into account quoting?
I have a command that produces a list of arguments, quoting then if neccesary (https://docs.python.org/3/library/shlex.html#shlex.quote). I need them to pass them as command arguments in a zsh script (...
1 vote
4 answers
228 views
Need shell script help - processing the same option multiple times
So I've ran into a bit of a wall, I have an option in my script that calls a function which allows me to specify a file/directory and then I want to parse that output into a menu tool (using dmenu in ...
5 votes
4 answers
995 views
Pass multiple files as a single option
I'm trying to build a wrapper to execute a tool multiple times, then concatenate some of the results. I'd like to pass two sets of files to my wrapper script, then run the tool for each pair of files. ...
2 votes
2 answers
552 views
Zsh Expanding Variables into Arrays or Lists
I looked through some of the posted threads and none of them cover my query. I have a simple line of code below which prints all the ASCII characters: echo {' '..'~'} I want to be able to use a ...
3 votes
3 answers
334 views
How to use associative array in Bash to get the current time in multiple locations?
I want to create a Bash script that outputs the following: Chile: 03:46am, Friday, 27 September, 2024 Tierra Del Fuego: 03:46am, Friday, 27 September, 2024 Falkland Islands: 03:46am, Friday, 27 ...
3 votes
1 answer
208 views
Treat unset variables as an error when substituting (set -u) ignores array expansion
I don't understand why the array expression is fine. $ set -eu $ echo "${envs[*]}" $ echo "${envs}" bash: envs: unbound variable How can I make bash fail also on such array ...
2 votes
3 answers
733 views
split and echo bash array with newlines to terminal
I create an array with a comma for delimiter: echo "${myarray[*]}" # prints: 22,3,2,0,22,4,5,8,22,4,3,6 I'd like to print it to terminal in chunks of four, with a newline and no comma ...
1 vote
1 answer
125 views
How to assign matching node values from xmlstarlet to an array in bash?
The loop below finds all of the nodes where the value equals "DOWNLOADING" and grabs the value of the corresponding "bytesdownloaded" node. I was expecting adlBytesDL1[0] to equal ...
7 votes
1 answer
290 views
Where are Perl arrays @0, @9999 documented?
$ perl -wle 'my @388=0..2;' Can't use global @388 in "my" at -e line 1, near "my @388" Execution of -e aborted due to compilation errors. $ perl -wle '@388=0..2;' $ Where can I ...
0 votes
3 answers
2k views
How to add a prefix to every element of an array in shell
I am reading inputs from user in my script with spaces, and those multiple inputs I want to use in a command further down by adding -l in front of each one of those inputs. Is there a way to do this ...
3 votes
1 answer
3k views
jq skip iteration over null
I am using jq 1.7 Data I am operating on info.json downloaded by yt-dlp yt-dlp --write-info-json --skip-download https://www.youtube.com/watch?v=vlIO-7Rpi7c JQ - Task Now I want to remove all array ...
0 votes
2 answers
331 views
Iterating arrays in TCL where array names have a numeric suffix
In TCL, I have a few arrays whose names have a numeric suffix (i.e., whose names end with a number), like below: array set ps0 [ list 0 15.885 1 55.43 1 0.254 2 0.227 3 0.177 ] array set ps1 [ list 0 ...