2022 Developer Survey is open! Take survey.
5 votes
Accepted

How can i use a parameter as an inner array-name to my script?

It looks like you may want to use a name reference variable (available in bash release 4.3 or later): #!/bin/bash declare -A num word word=( [a]='index_a' [b]='index_b' [c]='index_c' ) num=( [a]...
user avatar
  • 268k
3 votes

view my lowercase shell variables from a bash function using awk

With bash, you can get the list of variable names (though not the ones that have been declared but not assigned) into an array with: readarray -t Vars < <(compgen -v) You can filter that with ...
user avatar
2 votes

echo names and values of all env variables that start with "nlu_setting"

Both older answers are good, yet I came with my own: env | grep ^nlu_setting_ | while read kv; do echo "$kv"; done Doesn't distinguish for key and value, and uses grep, but that's exactly ...
user avatar
2 votes
Accepted

get value of variable which is prefixed by another variable in bash

app=(yahoo gmail) # ... declare ${app/%/_pid}=$! This, above, looks odd. While app is an array, just referencing $app will get the first element from the array, same as ${arr[0]}. So that would ...
user avatar
  • 115k
2 votes
Accepted

Curl against list domains from a file not working

You can read the domains from file to an array and loop for them. baseurl="https://csp.infoblox.com" B1Dossier="/tide/api/data/threats/state/host?host=" url="${baseurl}${...
user avatar
  • 6,335
1 vote
Accepted

Variable Scope in ZSH: How to access global variables from within function?

Your functions will see the variable that you have set earlier (and exported or not) provided they haven't been set in a subshell or not declared local to some function that has since returned. Your ...
user avatar
1 vote

How can I get the size of a variable, string, or array in bytes?

array1=($(find /etc -mindepth 1 -maxdepth 1 -type d)) Is wrong as it performs split+glob on the output of find to get the list (and the output of find without -print0 is not post-processable anyway). ...
user avatar
1 vote

Curl against list domains from a file not working

Use while loop: #!/bin/bash baseurl=https://csp.infoblox.com domains=/home/user/Documents/domainlist APIKey=<REDACTED> AUTH="Authorization: Token $APIKey" while read -r domain; ...
user avatar
  • 1,580
1 vote

Curl against list domains from a file not working

You seem to be iterating over the name of the file that holds the actual domains, which is why your code is not doing what you want it to do. You also seem to be outputting everything to the same file,...
user avatar
  • 268k

Only top scored, non community-wiki answers of a minimum length are eligible