Skip to content

Instantly share code, notes, and snippets.

@sevenissimo
Created June 30, 2022 19:21
Show Gist options
  • Select an option

  • Save sevenissimo/e9d38d379a19d300001ee404bae4511a to your computer and use it in GitHub Desktop.

Select an option

Save sevenissimo/e9d38d379a19d300001ee404bae4511a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#set +x
# Create an array named as param ($1) or 'FOO'
# and fill it with random numbers without naming it
rand() {
declare -n ref="${1:-FOO}"
for i in {1..10}; do
ref[$i]=$RANDOM
done
}
rand arr
echo "arr=${arr[@]}"
rand
echo "FOO=${FOO[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment