I have an array of string foo bar baz lorem ipsum
I'm passing this array to another bash script by appending a random password from output of openssl rand -hex 3
Expected array output is like
foo:a6f bar:0o0 baz:5!3 ....
How can I achieve this?
Here is one idea.
Expected array output is like foo:a6f bar:0o0 baz:5!3 ....
#!/usr/bin/env bash
array=(foo bar baz lorem ipsum)
for i in "${array[@]}"; do
IFS= read -r rand < <(openssl rand -hex 3) &&
new_array+=("$i":"$rand")
done
printf '%s\n' "${new_array[*]}"
I'm passing this array to another bash script by appending a random password from output of openssl rand -hex 3
Using a separate script and feeding the array.
The script named myscript
#!/usr/bin/env bash
new_array=()
for f ; do
IFS= read -r rand < <(openssl rand -hex 3) &&
new_array+=("$f":"$rand")
done
printf '%s\n' "${new_array[*]}"
At the command line.
initialize the array of strings.
array=(foo bar baz lorem ipsum)
Feed it against myscript.
myscript "${array[@]}"
Not sure how you would incorporate the code above in your script though, since we don't know where are the strings is coming from.
:and your newly created password to a string, call the script with that new string.