Skip to main content

Questions tagged [bash-array]

Filter by
Sorted by
Tagged with
7 votes
1 answer
363 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
2 votes
1 answer
431 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
4 answers
263 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
1 answer
326 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
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
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
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
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
7 votes
1 answer
428 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
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
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
0 votes
2 answers
143 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
498 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
-3 votes
1 answer
133 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
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
2 votes
1 answer
75 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
-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,475
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
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
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
0 votes
1 answer
524 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
1 vote
2 answers
192 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
0 votes
1 answer
753 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,502
-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
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