Skip to main content

Questions tagged [array]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
66 views

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 ...
Emily Lockhart's user avatar
1 vote
1 answer
84 views

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'...
Keelung's user avatar
  • 167
0 votes
3 answers
109 views

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 ...
EmberNeurosis's user avatar
4 votes
1 answer
140 views

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 (...
Petr's user avatar
  • 1,776
1 vote
4 answers
204 views

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 ...
hollowillow's user avatar
5 votes
4 answers
964 views

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. ...
Whitehot's user avatar
  • 245
2 votes
2 answers
523 views

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 ...
James Bond's user avatar
3 votes
3 answers
313 views

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 ...
ZPMMaker's user avatar
3 votes
1 answer
199 views

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 ...
Jakub Bochenski's user avatar
2 votes
3 answers
689 views

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 ...
bungee1980's user avatar
1 vote
1 answer
116 views

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 ...
 webbytr's user avatar
7 votes
1 answer
282 views

$ 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 ...
Dan Jacobson's user avatar
0 votes
3 answers
2k views

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
3k views

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,176
0 votes
2 answers
309 views

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
682 views

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
577 views

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
  • 3,318
1 vote
2 answers
4k views

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
  • 6,359
1 vote
2 answers
360 views

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
438 views

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
  • 554
2 votes
1 answer
582 views

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
111 views

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
496 views

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
643 views

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
304 views

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.8k
17 votes
5 answers
24k views

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
0 votes
1 answer
138 views

I'm attempting to write a function that writes arrays with a name that's passed in. Given the following bash function: function writeToArray { local name="$1" echo "$name" ...
Lee's user avatar
  • 549
0 votes
2 answers
63 views

I want to extract a specially formatted array from the list of current dir. $ ls Output: fileABC.ext1 filePQR.ext2 dirMNO dirFGH I want only the dir and files of specific extension I want an array ...
decipher's user avatar
  • 362
0 votes
1 answer
970 views

I'm using bash shell. I have this array representing file paths MY_FILES=(/path/to/file1 /tmp/abc.txt /tmp/test.sh /path/to/file2 /path/to/file3 /tmp/abc.txt) How can I form a new array of elements ...
Dave's user avatar
  • 2,808
0 votes
2 answers
496 views

So, I have a file array list in a bash shell, and I want to sort all the files in the array by the date modified, starting with the oldest being the first one in the array. However, I don't want to ...
Eduardo Perez's user avatar
1 vote
1 answer
346 views

Here is some simple test code. #!bin/bash cpm=(0 1 0.094) lv=1 attack=5 defense=9 stamina=16 echo $((cpm[lv])) mycpm=$((cpm[lv])) #mycpm=`echo "0.094" | bc -l` cq=`echo "$attack*$...
Tim50001's user avatar
0 votes
2 answers
1k views

I want to fetch some apis from github. so this is the code array=(link1 link2 link3 link4) readarray -t item < <(for i in ${array[@]} do curl -s "$i" | jq '.tag_name' done) ...
decipher's user avatar
  • 362
0 votes
1 answer
365 views

I have two arrays and want to print a value from ARRAY2 depending on the applicable value in ARRAY1. #!/usr/bin/env bash ARRAY1=(bb.service.sql bw.service.sql) ARRAY2=(bb bw) case $ARRAY1[@] in ${...
vrms's user avatar
  • 287
1 vote
1 answer
11k views

I try to convert my .json files to .csv with jq. I'm getting cannot index array with string value on all my values. .json { "organic_data": [ { "description": "...
pwrsheller's user avatar
4 votes
2 answers
492 views

Let's say I'd like to remove the first two and last three characters from all elements of an array e.g. results=( QK9H9UtADCgnG AlaLkCADjQ krsxseW8H1VrU 6nBG94ZbCWQ ) I'd like to end up with results=(...
don_crissti's user avatar
  • 85.7k
0 votes
1 answer
832 views

I have array with name 'arr' which has the following value - post-ro post-ro-1 post-ro-2 I have this variable: str="su scp [email protected]:/etc/bp/pg/pri/user.json /etc/bp/pg/pri" I want to ...
Madhavi Deshpande's user avatar
0 votes
2 answers
157 views

How may I loop over a set of PIDs delimited by spaces? I think I remember the first step is like making each element its own row? For my Firefox sessions they are quite a few PIDs: $ pidof firefox ...
von spotz's user avatar
  • 515
0 votes
1 answer
71 views

So in order to be versatile, I make a lot of functions and i want to define my own variable name when i call on that function. For basic text, numbers it works and this is how I do it function ...
WingZero's user avatar
2 votes
1 answer
579 views

I am trying to use regex for capturing some text pattern in an ouput of a command and create an array list_mqs. The problem is that this previous command get stuck and never terminates. So, when I use ...
dcubaz's user avatar
  • 23
0 votes
1 answer
166 views

Does anyone can explain me why the pid is not deleted from my pids list ? The for loop still occure the same number of time each time I go in this The var i is equal of the number of pids. So the loop ...
Kaleikini O'CONNOR's user avatar
4 votes
1 answer
6k views

I have the following string in bash "3.8,3.9,3.10" Is there a way using shell to convert it into a json array, i.e. ["3.8", "3.9", "3.10"]
pkaramol's user avatar
  • 3,109
0 votes
2 answers
596 views

I am trying to target 100+ directories to perform a copy. The whole script needs to be contained within one file; therefore, I can't have the directories saved in a separate file. I want to be able to ...
sflk1f0's user avatar
3 votes
1 answer
939 views

I'd like to pass an array to a bash function but I get a bad substitution error Example mapfile -t ray < <(parallel -j 0 echo ::: {1..10}) declare -p ray declare -a ray=([0]="2" [1]=...
Nickotine's user avatar
  • 554
1 vote
1 answer
3k views

I have following playbook ~ # cat demo.yml: - name: demo hosts: localhost gather_facts: no vars: set: task: type: var1 task: - type: var1 - type: var2 - type: ...
Rafal Niznik's user avatar
0 votes
1 answer
491 views

I'm having a problem with declaring array from STDOUT in Buildspec, which is part of Codebuild in AWS. Buildspec using Pure Bourne Shell, so I can't use this line in code declare -a available_envs=($(...
paras_san's user avatar
0 votes
1 answer
110 views

I am trying to make a functional script just using Partition Label, get that label, from the Label get the Device, and pass fsck -fy twice on each partition. #!/usr/bin/env bash # Filter partition by ...
Inukaze's user avatar
  • 47
-1 votes
2 answers
500 views

I have a comma-separated csv file with 50 lines. One column is for state names and the other column is for capitals (of the states). How do you make a loop where it counts the number of tokens (2, 3, ...
usuallystuck's user avatar
0 votes
1 answer
284 views

I’m using Zsh’s parameter expansion flags to split a string into an array. This works: string="one two" array=("${(f)string}") echo "${array[1]}" # Returns: # one This ...
user137369's user avatar
1 vote
1 answer
1k views

So, I am trying to use whiptail command to give users option to choose different things they want to install in their system. I use the whiptail --checklist command as below: name =$(whiptail --title &...
BishwashK's user avatar
1 vote
1 answer
750 views

I want to parse a csv file in zsh row by row and store it in an array (without the commas). Is it possible to import a single row into an array in zsh, then afterwards grab the next row? The issue is ...
Pogchamp_prob's user avatar

1
2 3 4 5
13