Skip to main content

Questions tagged [array]

A array is the simplest data-structure for storing items in continuously memory

0 votes
0 answers
7 views

define an array in c using a macro as length in C [migrated]

I want to defined an array, the length from a macro as below, #define A (2.5) #define B (2.0) #define LEN (A*B) // I know LEN is an integer, not decimal numbers static int array[LEN] // define ...
Keely Darien's user avatar
0 votes
3 answers
130 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 ...
Heyya's user avatar
  • 19
3 votes
1 answer
443 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 ...
Porcupine's user avatar
  • 2,056
0 votes
2 answers
35 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 ...
poppycock's user avatar
4 votes
1 answer
531 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 ...
CyberFoxar's user avatar
4 votes
4 answers
369 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 ...
Flux's user avatar
  • 2,978
0 votes
2 answers
1k views

Bash manage space separated list

I have a rather complex shell script which processes several list of values which are read from a file as space separated values e.g. SET1="value1 value2 value3" for i in ${SET1}; do ... ...
symcbean's user avatar
  • 5,831
1 vote
2 answers
165 views

Getting an array of files built from include array and exclude array containing globs

I am wanting to do the following: Define an array of globs that specify a base collection of files to include in a process. Define an array of globs that specify files to exclude from that process. ...
bmitc's user avatar
  • 107
1 vote
1 answer
335 views

How to save the output of a sliced array as separate items rather than a string, when set as a var?

When slicing an array the output is captured in a variable as a string. When the slice is used directly it will be separate items. How can I save a sliced array in a variable without it being turned ...
Nickotine's user avatar
  • 489
2 votes
1 answer
537 views

What is difference between these two declarations of associative arrays in Bash?

I am playing a bit with associative arrays in Bash and I found the following difference when declaring the exact same associative array with and without declare. The code is as follows: #!/usr/bin/env ...
chemacabeza's user avatar
0 votes
2 answers
58 views

Read new lines from file and compare with two arrays if one or more word exists the result should not be written

Big fan of stackoverflow. Am a beginner myself and have found a lot of help on this site but have run into problems now. Today I have a function like the following. I read a text file (data.txt) for ...
SweAndreas's user avatar
-1 votes
1 answer
255 views

Zsh string variable containing multi words must be assigned to an array

How to have Zsh string variable containing multi words separated by space be assigned to an array so that each word is the array element s='run help behind me' a=($s) m=${a[0]} n=${a[1]} print "m=...
user avatar
2 votes
2 answers
472 views

For loop through a variable vector

I have a for loop and case statements. The for loop has quite a bit element list and the case statement will assign an 1D array or a vector. These values will be used in for loop after. I have the ...
BircanA's user avatar
  • 21
0 votes
3 answers
243 views

In a bash script, loop through a bash array for input to a binary

I'm running bash. Suppose I have a binary mybinary that takes interactive user input. Suppose that mybinary takes attendee names as input until the user types q and presses Enter (q for "quit&...
Andrew's user avatar
  • 17.1k
9 votes
5 answers
12k views

How can I create a multidimensional array, or something similar, with bash?

I need to create a multidimensional array with bash and I read that there is no such thing as multidimensional arrays in bash . Here are my possible data, what they look like and what I need. This is ...
Santiago's user avatar
  • 225

15 30 50 per page
1
2 3 4 5
43