All Questions
39
questions
0
votes
1
answer
55
views
linux bash shell script - pass through function array variable
So in order to be versatile, I make a lot of functions and i want to define my own variable name when i call on that function.
For basic text, numbers it works and this is how I do it
function ...
1
vote
1
answer
3k
views
Ansible: set_fact after successful variable match in array
I have following playbook ~ # cat demo.yml:
- name: demo
hosts: localhost
gather_facts: no
vars:
set:
task:
type: var1
task:
- type: var1
- type: var2
- type: ...
0
votes
2
answers
69
views
get value of variable which is prefixed by another variable in bash
I'm running offlineimap on a bunch of accounts and want to check the exit code of each run and perform some actions accordingly.
I have 6 separate email accounts that I run against with a lot of code ...
0
votes
2
answers
941
views
For-loop - appending to arrays with iterator in the array name
I have the following problem. I have an array arr with some values. I want to sort each value into a set of different - and already declared - arrays earr$j, i.e. arr[0] into earr1, arr[1] into earr2 ...
2
votes
0
answers
231
views
for loop and appending over list of arrays
I am new to Bash scripting and presently find myself dealing with a small problem in working with for loops, arrays and variable assignment/substitution which I do not know how to solve. Since I am ...
0
votes
2
answers
314
views
Storing array as Environment variable to noninteractive shell with xargs
This is in continuation of Storing array as Environment variable to non-interactive shell - Unix & Linux Stack Exchange. Kusalananda, asked me to ask another question.
I want to find all markdown ...
0
votes
1
answer
164
views
Bash array arent adding elements to last
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# array=()
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# for i in 1 2 3 4
> do
> array+=($i)
> done
root@kali-linux:~/Softwares/...
1
vote
1
answer
895
views
Copy bash array to a variable which name is hold by another variable
There are many similar questions, but I didn't understand any answer as solution of the following problem:
I want to create a bash function which holds two arguments, first is a variable name and ...
0
votes
1
answer
789
views
User input to search bash array
folks--
I'm getting kinda stuck, here. I have a small script that will be incorporated into a larger script. This small piece is supposed to take a user input, and compare it to a list of stored ...
5
votes
3
answers
2k
views
How to convert file of strings separated by a new line to array
I have a file with data like this:
UserName
UserName
UserName
Each piece of data is separated by a new line.
I need that data to be converted to an array of strings and stored in a variable.
How ...
24
votes
1
answer
4k
views
What is the difference between $path and $PATH (lowercase versus uppercase) with zsh?
In FreeBSD 12, using the zsh shell, I noticed this difference when looking at $path (lowercase) versus $PATH (uppercase).
echo $path
/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /...
-1
votes
1
answer
3k
views
How to Force String Type on a Variable?
I have this script:
#!/bin/bash
USERS=("user1.com" "user2.co.uk" "user3.com")
PASSES=("pass1" "pass2" "pass3")
for i in ${USERS[@]}; do
echo ${PASSES[i]};
done
running this script outputs:
...
8
votes
1
answer
4k
views
Does `declare -a A` create an empty array `A` in Bash?
Does declare -a A create an empty array A in bash, or does it just set an attribute in case A is assigned to later?
Consider this code:
set -u
declare -a A
echo ${#A[*]}
echo ${A[*]}
A=()
echo ${#A[*...
6
votes
2
answers
519
views
How do I specify chance when setting a variable to random item in array?
Currently I do something like this to set a variable to a random item in an array:
array=("foo" "bar" "baz")
var=${array[$RANDOM % ${#array[@]} ]}
How would I do if I want to set $var to one of ...
0
votes
2
answers
72
views
Bash - How to put an array inside values of variable?
I have a web.txt file which contains:
youtube
facebook
google
My sh file contains:
readarray web < web.txt
url = www.website.com
Commands I have used:
readarray web < web.txt
url = www."$...