Skip to main content

Questions tagged [bash-array]

Filter by
Sorted by
Tagged with
7 votes
1 answer
392 views

Consider an associative array in bash (versions 5.2.15(1)-release and 5.2.21(1)-release): declare -A ufs=(); ufs["one"]=1; ufs["two"]=2; ufs["three"]=3 printf '> %s\n' ...
Chris Davies's user avatar
-3 votes
3 answers
159 views

In the below shell script I am passing an integer and a string array to a print function which should print each parameter separately, but I'm not able to. I don't want make a reference of passed ...
Harry's user avatar
  • 239
2 votes
1 answer
489 views

This question is similar to this one but it differs from it: Consider this array with string elements which may contain spaces: a@W:$ arr=("eins" "zwei" "eins plus zwei" &...
Adalbert Hanßen's user avatar
0 votes
2 answers
95 views

I have a pipeline using array jobs and need to change the number of inputs for some steps. I thought about testing uniq since the only part changing in my folders are the last four characters (the hap ...
Matteo's user avatar
  • 387
0 votes
4 answers
306 views

following example: string=" 'f o o' 'f oo' 'fo o' " array=($string) echo "${array[0]}" outputs: 'f while the expected output is: 'f o o' The only solution I came with is by ...
Zero's user avatar
  • 39
2 votes
3 answers
512 views

In the file groupAfiles.txt are the lines: file14 file2 file4 file9 I need a way to convert them to remove file and add /dev/loop and put them all in one line with a space between them. /dev/loop14 /...
user447274's user avatar
2 votes
1 answer
332 views

I have an array snapshots=(1 2 3 4) When I run printf "${snapshots[*]}\n" It prints as expected 1 2 3 4 But when I run printf "${snapshots[@]}\n" It just prints 1 without a ...
geckels1's user avatar
  • 173
0 votes
3 answers
187 views

I am trying to multiply array values with values derived from the multiplication of a loop index using bc. #!/bin/bash n=10.0 bw=(1e-3 2.5e-4 1.11e-4 6.25e-5 4.0e-5 2.78e-5 2.04e-5 1.56e-5 1.29e-5 1....
csnl's user avatar
  • 35
3 votes
2 answers
2k views

I want to download and extract a large zip archive (>180 GB) containing multiple small files of a single file format onto an SSD, but I don't have enough storage for both the zip archive and the ...
Kumaresh Balaji Sundararajan's user avatar
1 vote
1 answer
416 views

I've some associative arrays in a bash script which I need to pass to a function in which I need to access the keys and values as well. declare -A gkp=( \ ["arm64"]="ARM-64-bit" ...
c10's user avatar
  • 13
3 votes
4 answers
3k views

#!/usr/bin/bash ARGENT=("Nous devons économiser de l'argent." "Je dois économiser de l'argent.") BIENETRE=("Comment vas-tu?" "Tout va bien ?") aoarrs=("${...
John Smith's user avatar
2 votes
1 answer
357 views

I was trying to create a bash "multidimensional" array, I saw the ideas on using associative arrays, but I thought the simplest way to do it would be the following: for i in 0 1 2 do ...
Wellington de Almeida Silva's user avatar
1 vote
1 answer
1k views

Is there a case where mapfile has benefits over arr+=(input)? Simple examples mapfile array name, arr: mkdir {1,2,3} mapfile -t arr < <(ls) declare -p arr output: declare -a arr=([0])="1&...
Nickotine's user avatar
  • 554
0 votes
3 answers
206 views

I can't append to an array when I use parallel, no issues using a for loop. Parallel example: append() { arr+=("$1"); } export -f append parallel -j 0 append ::: {1..4} declare -p arr ...
Nickotine's user avatar
  • 554
1 vote
3 answers
4k views

I have a function (not created by me) that outputs a series of strings inside of quotes: command <args> “Foo” “FooBar” “Foo Bar” “FooBar/Foo Bar” When I try to assign it to an array (Bash; BSD/...
Allan's user avatar
  • 1,100
3 votes
2 answers
770 views

I have an input file, names.txt, with the 1 word per line: apple abble aplle With my bash script I am trying to achieve the following output: apple and apple apple and abble apple and aplle ...
duda13's user avatar
  • 33
7 votes
1 answer
437 views

The following script fails when run with bash 4.4.20(1) #!/bin/bash bar() { local args=("y") } foo() { local -r args=("x") bar } foo with error line 3: args: readonly ...
Dennis's user avatar
  • 73
0 votes
2 answers
512 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
361 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
0 answers
32 views

let the given array is array=(12:45 01:30 02:02 02:55 03:55) so how to find the time let, 12:50 is lie between which two time frame(with index) is bash script array=(12:45 01:30 02:02 02:55 03:55) ...
Bhawishya Khanal's user avatar
4 votes
2 answers
2k views

I have an array tokens which contains tokens=( first one two three last ). How do I obtain the values ( one two three ) if I do not know how many numbers are in the array? I want to access everything ...
sriganesh's user avatar
  • 111
1 vote
1 answer
986 views

I have a long line that comes as output from a git command: a=$(git submodule foreach git status). It looks like this: a = "Entering 'Dir1/Subdir' On branch master Your branch is up to date with '...
Zaida's user avatar
  • 133
0 votes
2 answers
155 views

Suppose, I have 1 file in a folder named B.py Using this script, I make 3 files within that folder. The files are A.py B.py C.py. read -r -p "Enter the filenames: " -a arr for filenames in &...
Mega Bang's user avatar
  • 159
0 votes
2 answers
200 views

I am trying to grab results from lshw and add them to a a bash array so I can create a new string. I am using lshw -class disk |egrep -A 7 .'-d' |grep 'product' |cut -b 17- the output looks like this ...
xtree's user avatar
  • 1
0 votes
2 answers
506 views

I'm doing a script in bash where I need to declare arrays inside loops, so I made it like this: variable=suffix declare -a prefix_$variable='(item1 item2)' then I should be able to use "prefix_$...
user2934303's user avatar
2 votes
5 answers
4k views

I have 2 arrays to prcoess in bash script simultaneously. First array contains sort of lables. Second array contains values, as under LABELS=(label1 label2 label3 labe4 ) VALUES=(91 18 7 4) What's ...
Sollosa's user avatar
  • 2,009
-3 votes
1 answer
140 views

I have an array declared in my script. NAME[0]=Deepak NAME[1]=Renuka NAME[2]=Joe NAME[3]=Alex NAME[4]=Amir echo "All Index: ${NAME[*]}" echo "All Index: ${NAME[@]}" There are two ...
Tom's user avatar
  • 5
0 votes
0 answers
29 views

The last elif arm does not get executed: #!/usr/bin/bash searches=("feet" "axilas" "lactant") length=${#searches[@]} searchFunction() { echo "Enter the respective ...
John Smith's user avatar
5 votes
2 answers
15k views

The following post solution works as expected: How to pass an array as function argument? Therefore - from his answer: function copyFiles() { arr=("$@") for i in "${arr[@]}"...
Manuel Jordan's user avatar
4 votes
1 answer
2k views

With the following code: #! /bin/bash declare -a arr=("element1" "element2" "element3&...
Manuel Jordan's user avatar
2 votes
1 answer
81 views

The following code is meant to look for subdirectories in ~/Downloads. I run it with . ./script.sh. It will find them even when the user submits an incomplete name. #!/usr/bin/bash echo -e "\...
John Smith's user avatar
0 votes
1 answer
309 views

The script will echo the different values stored in an array based on user input. However, the output is not correct and the wrong value is echoed. AA_P=/root/run_Scripts/AA_P_run.sh AA_S=/root/...
Gee_k's user avatar
  • 27
-1 votes
1 answer
1k views

I with to monitor if my access points pingable and store results into 0-1 string I wrote a script but it works wrong #/bin/bash access_points=("tplink2" "redmi1") #results=("...
Dims's user avatar
  • 3,485
0 votes
3 answers
729 views

I have an array with some data: array1=( AAA BBB CCC DDD ) I want to populate an array of results from calling a certain API with the data in array1 and at the same time I want to show the progress ...
dentex's user avatar
  • 163
0 votes
2 answers
1k views

I have the following problem. I have an array arr with some values. I want to sort each value into a set of different - and already declared - arrays earr$j, i.e. arr[0] into earr1, arr[1] into earr2 ...
UserAthos's user avatar
2 votes
0 answers
316 views

I am new to Bash scripting and presently find myself dealing with a small problem in working with for loops, arrays and variable assignment/substitution which I do not know how to solve. Since I am ...
UserAthos's user avatar
1 vote
2 answers
2k views

Perhaps this is a stupid question but two hours on Google hasn't turned up anything on point. Simply, does a difference exist in Bash between: X=" a b c " and X=( a b c ) The former ...
ebsf's user avatar
  • 399
0 votes
0 answers
19 views

I'm trying to make an array in a bash script. I keep running into a problem even though I feel like I've followed tutorials correctly. #!/bin/bash myArray=("cat" "dog" "mouse&...
Brad's user avatar
  • 1
4 votes
2 answers
1k views

In reading through the source to fff to learn more about Bash programming, I saw a timeout option passed to read as an array here: read "${read_flags[@]}" -srn 1 && key "$REPLY&...
qmacro's user avatar
  • 143
2 votes
1 answer
3k views

I have two different arrays with the same length: s=(c d e f g a b c) f=(1 2 3 1 2 3 4 5) how can I mix/merge/combine this two arrays, so I would get this output: c1 d2 e3 f1 g2 a3 b4 c5
nath's user avatar
  • 6,114
0 votes
1 answer
538 views

I am using a bash script to call rsync commands. Have decided to collect some options in an array called oser. The idea is to look at what's different in the two invocations and put that into the ...
Pietru's user avatar
  • 403
2 votes
1 answer
965 views

I'm trying to build a basic REPL in bash. The script dynamically populates a list of files in a directory for the user to run. File space: | |\ scripts/ || script1.sh || script2.sh | \ shell/ | ...
user3116064's user avatar
1 vote
2 answers
201 views

I'm having a bit of difficulty understanding parallel procedures. Atm I'm trying to mass wipe hard drives, so have created a script, however it won't run in parallel. for i in "${!wipe[@]}"; ...
Earthwormben's user avatar
3 votes
3 answers
4k views

I need to process some strings containing paths. How do I split such a string by / as delimiter resulting in an unknown number of path-parts and how do I, in the end, extract the resulting path-parts? ...
von spotz's user avatar
  • 515
0 votes
1 answer
765 views

So, Let's say i have an array arr, with two element in it: read -a arr <<< "$@" where i would then either use it in a function or script and input two string or element like so: ...
secemp9's user avatar
  • 2,520
0 votes
2 answers
715 views

#!/bin/bash mat_1=(ServerAB ServerFR ServerPE ServerAM ServerHU) st="mat_1"; indirect_var='${'${st}'[@]}' #(Please, see the "--Desired Ouput Section--" in comments) #----- What ...
dcubaz's user avatar
  • 23
-1 votes
4 answers
2k views

I'm new to bash script learning and I'm quiet confused how to do this code. array1=(23 34 23 12 11 32 12 12 12 21) array2=(12 13 14 43 42 23 32 11 10 22) These are the two arrays, and I need to get ...
Grace's user avatar
  • 1
-1 votes
1 answer
1k views

So, i already know how to successfully read every N lines in parallel, and run a command on each of those lines: while read -r i && read -r a && read -r b && read -r c &&...
secemp9's user avatar
  • 2,520
0 votes
2 answers
2k views

How can I use this shell script with for loop and an array. I would like to call create condition for quality gate creation of sonarqube with a for loop. Example: #!/bin/bash --login echo "...
user1628's user avatar
0 votes
0 answers
239 views

I'm having trouble assigning values to a specific bash index, but apparently only when the index variable is set using a while read loop. Taking this code as a test example: #!/bin/bash read -d '' ...
steinocaro's user avatar