Skip to main content

All Questions

Tagged with
2 votes
1 answer
197 views

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

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

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

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
2 votes
1 answer
258 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
  • 173
0 votes
3 answers
117 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
3 votes
2 answers
2k 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
333 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
3k 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
287 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
3 answers
3k 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,090
3 votes
2 answers
612 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
413 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
421 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
300 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

15 30 50 per page
1
2 3 4 5