Bash Programming

bash script: Movie Recommendation Script


#!/bin/bash

# Function to recommend movies based on user ratings
recommend_movies() {
user_rating=$1

if [ $user_rating -ge 8 ]; then
echo "You might enjoy watching Inception or Interstellar."
elif [ $user_rating -ge 6 ]; then
echo "You could watch The Dark Knight or Avengers."
else
echo "Maybe try watching a comedy like Deadpool or a classic like The Godfather."
fi
}

# Example of using the function to recommend movies
echo "Enter your rating (out of 10) for movies: "
read rating

recommend_movies $rating

This bash script defines a function `recommend_movies` that takes a user rating as input and recommends movies based on that rating. If the user rating is 8 or higher, it recommends watching “Inception” or “Interstellar”. If the rating is between 6 and 8, it suggests “The Dark Knight” or “Avengers”. For ratings below 6, it recommends watching a comedy like “Deadpool” or a classic like “The Godfather”.

The script then prompts the user to enter their rating for movies, reads the input, and calls the `recommend_movies` function with the user’s rating as an argument to provide movie recommendations based on their input.

This script can be expanded further to fetch user preferences and movie data from a database or API, making the movie recommendations more personalized and dynamic.