Skip to main content

Questions tagged [bash-array]

Filter by
Sorted by
Tagged with
1 vote
0 answers
115 views

I have thousands or more than thousands of files like A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=xxx23,celltracefile_DUL1_3.bin.gz A20200727.2015+0200-2030+0200_SubNetwork=ppp,MeContext=...
Indranil's user avatar
1 vote
2 answers
2k views

I am trying to add an element to a bash array. I looked at this question and tried to follow its advice. This is my code: selected_projects=() for project_num in ${project_numbers[@]}; do ...
chama's user avatar
  • 113
0 votes
2 answers
801 views

I want my /etc/passwd file to be as an array like this [user_id] => [home_directory] e.g. [0] => "/root" [1000] => "/home/user1" [1001] => "/home/user2&...
Mahdi's user avatar
  • 19
1 vote
2 answers
398 views

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable? ~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str ) echo "${array1[...
glarry's user avatar
  • 974
-1 votes
1 answer
361 views

I am trying to get an error message if one of the disks is filed more than 80%. So we have two arrays which have the data of disk partitions (they can have 3 partitions like in this example or more, ...
trustbyte's user avatar
0 votes
1 answer
381 views

I am trying to get the files from S3 bucket,starting with certain prefix. To do so am using aws cli command in the bash script. Below is my code #!/bin/bash FILESIZE=$(mktemp) declare -a files=( "...
clarie's user avatar
  • 95
0 votes
1 answer
562 views

Aim I am using multiple text files to set variables and array variables. These are the input arguments to a MATLAB function, that iteratively creates url download strings based on these variables, ...
liaml's user avatar
  • 3
0 votes
2 answers
645 views

I am trying to find out if certain RPM packages exists in an array. if any of the package is missing it will exit with the message "Package doesnt exist" .Here is my code #!/bin/bash echo "Checking ...
achak01's user avatar
  • 21
2 votes
1 answer
267 views

I am working with a server running Ubuntu 18.01 LTS and I'm trying to automate the backup of multiple virtual machines. I have the VM names in an array and then a for loop to shut down, backup and ...
Jaden's user avatar
  • 51
0 votes
1 answer
2k views

Suppose I have this code: for i in $(find * -type f -name "*.txt"); do # echo [element by it's index] done How do I access, if possible, an element by it's index?
schrodingerscatcuriosity's user avatar
1 vote
1 answer
107 views

I'm trying to write a script to tailor my dotfile setup to each machine using git update-index -skip-worktree but it keeps chopping up the paths. I'm passing arrays starting with commands where every ...
Joshua Ferguson's user avatar
4 votes
1 answer
4k views

I don't understand why "${ARRAY[@]}" gets expanded to multiple words, when it's quoted ("...")? Take this example: IFS=":" read -ra ARRAY <<< "foo:bar:baz" for e in "${ARRAY[@]}"; do echo $...
Shuzheng's user avatar
  • 5,019
1 vote
0 answers
301 views

The values present in indexArray are: 1 4 3 2 Below is the code snippet(This is not the complete code): while read -r line;do position=${indexArray[$counter]} # No value is assigned to "position" ...
Deepak Jain's user avatar
1 vote
1 answer
1k views

i'm trying to generate a script that ftp some files to a server using lftp. when i run these commands in shell: DBNAME=TESTDB ls -t /data*/${DBNAME,,}Backup/$DBNAME.0.db21.DBPART000.`date +%Y%m%d`...
BlackCrystal's user avatar
1 vote
2 answers
2k views

I've got an array that contains duplicate items, e.g. THE_LIST=( "'item1' 'data1 data2'" "'item1' 'data2 data3'" "'item2' 'data4'" ) Based on the above, I want to create an associative array that ...
Bart's user avatar
  • 2,314
23 votes
3 answers
11k views

VAR=a,b,c,d # VAR=$(echo $VAR|tr -d '\n') echo "[$VAR]" readarray -td, ARR<<< "$VAR" declare -p ARR Result: [a,b,c,d] declare -a ARR=([0]="a" [1]="b" [2]="c" [3]=$'d\n') How can I tell ...
user1156544's user avatar
5 votes
1 answer
579 views

I have a piece of code which works, something like this (note this is inside CloudFormation Template for AWS auto deployment): EFS_SERVER_IPS_ARRAY=( $(aws efs describe-mount-targets --file-system-id ...
Carmageddon's user avatar
1 vote
2 answers
535 views

I'm trying to learn more bash by updating my bash_profile so that I can quickly do some adb commands that I usually have to copy-paste. I found I was creating many similar functions that all looked ...
Travesty's user avatar
1 vote
2 answers
3k views

I trying to run command recon-all with GNU parallel freesurfer preproc i have a bash array of list of patients to run 8 patents simultaneously: root@4d8896dfec6c:/tmp# echo ${ids[@]} G001 G002 G003 ...
Relyativist's user avatar
7 votes
2 answers
10k views

Is there a way to find the length of the array *(files names) in zsh without using a for loop to increment some variable? I naively tried echo ${#*[@]} but it didn't work. (bash syntax are welcome ...
Cristiano's user avatar
3 votes
3 answers
8k views

I have an array like this: array=(1 2 7 6) and would like to search for the second largest value, with the output being secondGreatest=6 Is there any way to do this in bash?
user avatar
2 votes
2 answers
9k views

I have a array: ARRAY=(12.5 6.2) I wish to return the maximum value in ARRAY which Output is 12.5 Anyone can share me ideas? I have try this: max=0 for v in ${ARRAY[@]}; do if (( $v > $max )...
Shi Jie Tio's user avatar
1 vote
1 answer
392 views

If we: Define an array; and then.. Define a function; and want to.. Call that array from inside the function.. We can. Like so: Input: myArray=('1' '2' '3' '4' '5') myFunction () { local -n myList=...
voices's user avatar
  • 1,342
1 vote
1 answer
1k views

I found the following example from here. But I can't understand how is array arr is being defined. a='domain.de;de;https' $ arr=(${a//;/ }) What is the advantage of defining it like this? Actually, ...
Porcupine's user avatar
  • 2,176
1 vote
2 answers
229 views

Can the below code be easily achieved with minimum coding. $ cluster1=(x y) $ cluster2=(a b) $ cluster3=(m) $ my=$((${cluster1[0]+1}+${cluster2[0]+1}+${cluster2[0]+1})) $ echo $my 3 $ my=$((${...
Bharat's user avatar
  • 814
2 votes
1 answer
121 views

Consider the following example, it seems it's working fine with the index 0: $ a1=(1 2 3) $ a2=(a b c) $ for x in a1 a2; do echo "${!x}"; done 1 a $ for x in a1 a2; do echo "${!x[0]}"; done 1 a ...
NarūnasK's user avatar
  • 2,555
0 votes
2 answers
2k views

Say I have these two "lists": #!/usr/bin/env bash git fetch origin; first_list=( ); second_list=( ); git branch --merged "remotes/origin/dev" | tr -d ' *' | while read branch; do first_list+=(...
Alexander Mills's user avatar
0 votes
1 answer
174 views

I'm trying to grep all load averages & put them in an array. What should be the exact way, keeping in mind the followings requirements. Defining Array: LA= ("one" "five" "fifteen") LA= (`(uptime ...
Sollosa's user avatar
  • 2,009
1 vote
1 answer
6k views

we want to set variable that includes words as array folder_mount_point_list="sdb sdc sdd sde sdf sdg" ARRAY=( $folder_mount_point_list ) but when we want to print the first array value we get all ...
yael's user avatar
  • 14.1k
38 votes
15 answers
52k views

Is there a simple way to reverse an array? #!/bin/bash array=(1 2 3 4 5 6 7) echo "${array[@]}" so I would get: 7 6 5 4 3 2 1 instead of: 1 2 3 4 5 6 7
nath's user avatar
  • 6,114
17 votes
4 answers
18k views

Suppose I have a graphical program named app. Usage example: app -t 'first tab' -t 'second tab' opens two 'tabs' in that program. The question is: how can I execute the command (i.e. app) from within ...
Flux's user avatar
  • 3,318
0 votes
1 answer
1k views

Is there a way to pass a string value as env variable and have bash recognize it as an array? In other words, is there some special string format that tells bash that the string is an array? Or is ...
Alexander Mills's user avatar
9 votes
3 answers
26k views

I'm trying to delete range of array element but it's fail.. My array root@ubuntu:~/work# echo ${a[@]} cocacola.com airtel.com pepsi.com Print 0-1 array looks ok root@ubuntu:~/work# echo ${a[@]::2} ...
Rahul Patil's user avatar
  • 25.6k