Skip to main content

Questions tagged [bash-array]

2votes
1answer
198views

How can I take a sub-array in bash of the first N elements of a string array with elements containing spaces?

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
0votes
2answers
45views

pipe to uniq from a variable not showing the desired output

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
0votes
4answers
172views

bash - slice quoted substrings delimited by spaces into array

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
2votes
3answers
434views

Replace prefix string from lines in a file, and put into a bash array

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
2votes
1answer
260views

Why does printing an array with @ using printf in bash only print the first element?

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
0votes
3answers
117views

bash array multiplication using bc

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
3votes
2answers
2kviews

How to extract and delete contents of a zip archive simultaneously?

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
1vote
1answer
333views

Access values of associative array whose name is passed as argument inside bash function

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
3votes
4answers
3kviews

How do I select an array to loop through from an array of arrays?

#!/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
2votes
1answer
289views

What happens if I start a bash array with a big index?

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
1vote
1answer
743views

Creating and appending to an array, mapfile vs arr+=(input) same thing or am I missing something?

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
0votes
3answers
164views

Unable to append to array using parallel

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
1vote
3answers
3kviews

Bash: converting a string with both spaces and quotes to an array

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,090
3votes
2answers
612views

Iterating over array elements with gnu parallel

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

Bash 4.4 local readonly array variable scoping: bug?

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

153050per page
close