Questions tagged [array]
A array is the simplest data-structure for storing items in continuously memory
641 questions
0votes
3answers
40views
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 ...
4votes
1answer
89views
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 (...
1vote
4answers
114views
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 ...
5votes
4answers
814views
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. ...
2votes
2answers
274views
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 ...
0votes
0answers
26views
Where is ZFS keeping record of my faulted disks?
I had multiple drives in a ZFS array drop due to read errors yesterday. After powering down the machine to swap in a replacement for one of the drives, I was surprised to find that the drives ...
3votes
3answers
232views
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 ...
3votes
1answer
129views
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 ...
1vote
3answers
326views
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 ...
1vote
1answer
83views
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 ...
7votes
1answer
271views
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 ...
0votes
3answers
936views
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 ...
3votes
1answer
2kviews
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 ...
0votes
2answers
177views
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 ...
4votes
1answer
592views
Why does filtering a bash array using negative pattern matching and parameter expansion have unexpected results?
I'm doing a small-ish pure bash script to roll dice; as such I'm having to manipulate arrays. I want to do something akin to a filter operation in other languages: extract some of the things in the ...