Skip to content

Instantly share code, notes, and snippets.

@MohamedElashri
Last active September 14, 2024 07:15
Show Gist options
  • Save MohamedElashri/bbbec6c367b2f90203e22e4bc77d0b35 to your computer and use it in GitHub Desktop.
Save MohamedElashri/bbbec6c367b2f90203e22e4bc77d0b35 to your computer and use it in GitHub Desktop.
Interactive bash script that tells you if you need to write bash or python script for a particular case

Criteria for using Bash scripts instead of Python:

  1. The problem is easy to solve
  2. I don't need to do any math beyond simple addition or multiplication
  3. I don't need concurrency
  4. I don't need data structures
  5. I don't need functional programming code style
  6. I don't need to work on Windows
  7. I don't care about performance
#!/bin/bash
echo "Please answer the following questions with 'yes' or 'no'."
use_bash=true
# Question 1
read -p "Is the problem easy to solve? (yes/no): " ans1
if [ "$ans1" != "yes" ]; then
use_bash=false
fi
# Question 2
read -p "Do you need to do math beyond simple addition or multiplication? (yes/no): " ans2
if [ "$ans2" == "yes" ]; then
use_bash=false
fi
# Question 3
read -p "Do you need concurrency? (yes/no): " ans3
if [ "$ans3" == "yes" ]; then
use_bash=false
fi
# Question 4
read -p "Do you need data structures? (yes/no): " ans4
if [ "$ans4" == "yes" ]; then
use_bash=false
fi
# Question 5
read -p "Do you need functional programming code style? (yes/no): " ans5
if [ "$ans5" == "yes" ]; then
use_bash=false
fi
# Question 6
read -p "Do you need to work on Windows? (yes/no): " ans6
if [ "$ans6" == "yes" ]; then
use_bash=false
fi
# Question 7
read -p "Do you care about performance? (yes/no): " ans7
if [ "$ans7" == "yes" ]; then
use_bash=false
fi
# Conclusion
if [ "$use_bash" == "true" ]; then
echo "Based on your answers, you can use a Bash script."
else
echo "Based on your answers, you should consider using Python."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment