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]...
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 ...
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 ...
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 ...
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}${...
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 ...
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). ...
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; ...
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,...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
variable × 1110bash × 576
shell-script × 307
shell × 228
scripting × 74
awk × 67
quoting × 63
sed × 62
linux × 53
variable-substitution × 42
string × 38
array × 37
function × 37
environment-variables × 36
echo × 36
text-processing × 34
grep × 32
zsh × 31
test × 25
for × 23
pipe × 21
ksh × 21
read × 21
command-line × 20
find × 20