Skip to main content

Questions tagged [bash-array]

The tag has no usage guidance.

2 votes
1 answer
104 views

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
  • 163
0 votes
3 answers
63 views

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
  • 35
2 votes
2 answers
777 views

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

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

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

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

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
  • 489
0 votes
3 answers
139 views

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

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,060
3 votes
2 answers
356 views

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
  • 33
7 votes
1 answer
380 views

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
  • 73
0 votes
2 answers
338 views

Sort file array list in bash by date and bypass argument limit

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

Completed stumped by trying to use a decimal value in an array for Bash

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

How to find the user input time lies between which two time frame stored in array in bash script [duplicate]

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

How to slice an indexed array to obtain all elements between the first and last index?

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
  • 101

15 30 50 per page
1
2 3 4 5 6