Questions tagged [array]
A array is the simplest data-structure for storing items in continuously memory
640 questions
4
votes
1
answer
87
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
114
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
813
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
269
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 ...
0
votes
0
answers
26
views
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 ...
3
votes
3
answers
231
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
128
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 ...
1
vote
3
answers
323
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
82
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
271
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
930
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
2k
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
176
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 ...
4
votes
1
answer
592
views
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 ...
4
votes
4
answers
478
views
How to sort the list of positional parameters in POSIX sh
Is there a way to sort the list of positional parameters in POSIX sh? Each positional parameter could contain arbitrary characters (e.g. spaces, newlines, tabs, etc.). The sort algorithm should be ...