Bash Script to Predict Rich Age

Would you like to know when you'd get rich? Here's a little bash script (thanks NetworkChuck Academy) that might help. Create an executable file, call it getrichquick.sh and paste the following content inside: #!/bin/bash # echo "What is your name?" read name sleep 1 echo "How old are you?" read age sleep 1 echo "Hello,$name, your are $age years old." rich_age=$((($RANDOM%11) + $age)) echo "I'm looking into your future..." echo "Calculating..." echo "......." sleep 1 echo "**....." sleep 1 echo "****..." sleep 1 echo "******." echo "Hello,$name, you will be $rich_age when you become rich!" Save getrichquick.sh and run it. It's a fun little exercise. I tried it on my wife and expression was priceless. The exercise was a nice introduction into the $RANDOM variable in bash. $RANDOM variable helps to generate random numbers from 0 - 32767. This is useful in many DEVOPS tasks combined with the modulo operator (%). $(($RANDOM % 10)) simply means divide a random number from 0 - 32767 and give the remainder. The aim of the operation is to generate numbers from 0 - 9. If you are interested in integers from 1-10, then the operation becomes... $(($RANDOM + 1)) Devops use cases Random server selection for Load Balancing purpose Here's an example randomly choosing a server among three choices: servers=("server1" "server2" "server3") index=$(($RANDOM % 3)) echo "Deploying to ${servers[$index]}" Result... Deploying to server2 This is used for  - Load balancing - Blue-green deployments - Canary deployments #DevOps #Linux #Bash #ShellScripting #Automation #CloudEngineering  #DevOpsLearning #TechLearning #InfrastructureAsCode  #PlatformEngineering #DeveloperTips #CodingTips

To view or add a comment, sign in

Explore content categories