Reputation: 7
I would like to realise the following in Linux-Almalinux: So i would like to add 5 records with a new random word in it.
Problem is that following code will add N records with the same word. How can i some how add or something or maybe some temp variabele where i can delete this after every while loop...
So when INPUT_NUMBER is 5 then it adds 5 records with 5 random different names
local word=$(sort -R names.list | head -1)
Local INPUT_NUMBER=${2}
while [[ 1 -le $INPUT_NUMBER ]]
do
create_record ${word} ${Domain}
((i = i + 1))
done
Thanks in advance!
I tried to think about a solution but since im more experienced with JAVA, these WHILE/IF is completely different in Linux and more complex.
Upvotes: -1
Views: 70
Reputation: 204456
Untested since you didn't provide any sample input/output and create_record
isn't a common command that most people have (I don't) but this might be what you want:
shuf -n "$n" names.list | xargs -I {} -n 1 create_record {} "$Domain"
Upvotes: 0
Reputation: 782166
Put N words in an array and loop over the array.
local n=$2
local words=($(sort -R names.list | head -n "$n"))
for word in "${words[@]}"
do
create_record "${word}" "${Domain}"
done
Upvotes: 0