Skip to main content

All Questions

-2 votes
1 answer
70 views

Associative Array contains filenames and paths

I have a pipeline that deploys scripts into a temporary dir. I need to rellocate them into their actual proper directory. #!/usr/bin/sh DEPLOY_HOME=/opt/xxx function getDeployedFiles { ls ${...
KrOo Pine's user avatar
  • 107
2 votes
1 answer
564 views

What is difference between these two declarations of associative arrays in Bash?

I am playing a bit with associative arrays in Bash and I found the following difference when declaring the exact same associative array with and without declare. The code is as follows: #!/usr/bin/env ...
chemacabeza's user avatar
1 vote
1 answer
53 views

What <COMMAND> will make `declare -A ASSOCIATIVEARRAY=( $( <COMMAND> ) )` work?

bash evaluates the following expression without any objections: declare -A SPANISH=( [rojo]=red [verde]=green [azul]=blue ) ...but it does not like this one one bit: declare -A SPANISH=( $( echo &...
kjo's user avatar
  • 16.2k
0 votes
4 answers
447 views

Can't seem to access associative array with named reference in bash

# SETUP PHP81 SYMLINKS declare -A cgi=([path]="/opt/remi/php81/root/usr/bin/php-cgi" [filename]="php-cgi81") declare -A config=([path]="/opt/remi/php81/root/usr/bin/php-config&...
Corey Rosamond's user avatar
0 votes
0 answers
524 views

Associative array in shell script

I am trying to map a hostname to a queue manager name using the following array. I get an error with bad array script. What am I doing wrong here declare -A managers while read -r mgr host; do ...
MO12's user avatar
  • 409
0 votes
0 answers
218 views

Unexpected behavior during index assignment in a Bash array [duplicate]

I'm having trouble assigning values to a specific bash index, but apparently only when the index variable is set using a while read loop. Taking this code as a test example: #!/bin/bash read -d '' ...
steinocaro's user avatar
4 votes
4 answers
2k views

zsh testing existence of a key in an associative array via indirect expansion

So I know that you can test for the existence of a regular parameter via indirect expansion by doing something like: foo=1 bar=foo (( ${(P)+bar} )) && print "$bar exists" And I know you can ...
Matt Wilder's user avatar
1 vote
0 answers
2k views

How to make a simple menu in bash from an associative array

I am refactoring a script that displays a text menu similar to this: Select a mounted BTRFS device on your local machine to backup to. 1) 123456789abc-def012345-6789abcdef012 (/) 2) 123456789abc-...
MountainX's user avatar
  • 18.8k
2 votes
1 answer
6k views

how to combine 2 arrays into one associative array

i need to combine ARRAY1 and ARRAY2 into an associative array like ARRAY. i'm using this code: mapfile -t ARRAY1 < <(/bin/awk '{ print $ 1 }' /output/gen_branch) mapfile -t ARRAY2 < <(...
BlackCrystal's user avatar
0 votes
0 answers
172 views

bash: how to pass variables to a loop within a process substitution

How do you pass variable values within a process substitution to a loop within that process substitution? I'm reading a csv file into an associative array, and while reading each line, I would like ...
gj.'s user avatar
  • 11
0 votes
0 answers
19 views

associative array execution order problem [duplicate]

in a bash script i'm using an associative array to create tables, tablespaces, indexes and partitions in my database. this is the script (the main script is too long with complicated queries so i ...
BlackCrystal's user avatar
1 vote
2 answers
2k views

Merge duplicate keys in associative array BASH

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

Create persistent array in bash

I want an associative array in my bashrc file and I want to add to or delete from it whenever needed, but if I put the array declaration in the bashrc file it will get redeclared every time bash is ...
aderchox's user avatar
  • 751
6 votes
3 answers
12k views

linux bash dictionary check if empty

How to check if a dictionary (associative array) is empty? I just declare one using declare -A dict. I want to know if it is just declared but not have any key.
focus zheng's user avatar
2 votes
1 answer
5k views

What does declaring a bash array with -A do?

In Example_1, when i have declared city to be an array with declare -A, why is Bangalore output first when the array is printed in the for loop? Bangalore Remote Kolkata Ahmedabad Hyderabad Pune ...
superman's user avatar

15 30 50 per page