Code: Select all
# apt install jq
Code: Select all
#!/bin/bash
# Prompt the user for the movie title
echo "Enter the movie title:"
read movie_title
# Set the API key
api_key="4664a2b1"
# Get the movie information
movie_info=$(curl -s "http://www.omdbapi.com/?apikey=$api_key&t=$movie_title")
# Extract the movie's title, year, and plot
title=$(echo "$movie_info" | jq -r ".Title")
year=$(echo "$movie_info" | jq -r ".Year")
plot=$(echo "$movie_info" | jq -r ".Plot")
# Print the movie information
echo "$title ($year)"
echo "$plot"
# Extract the movie's rating
rating=$(echo "$movie_info" | jq -r ".imdbRating")
# Print the movie's rating
echo "The IMDB-rating for $movie_title is $rating/10"
Example output:
Code: Select all
hallvor@debian-thinkpad:~$ ./get_movie_info.sh
Enter the movie title:
Platoon
Platoon (1986)
Chris Taylor, a neophyte recruit in Vietnam, finds himself caught in a battle of wills between two sergeants, one good and the other evil. A shrewd examination of the brutality of war and the duality of man in conflict.
The IMDB-rating for Platoon is 8.1/10
hallvor@debian-thinkpad:~$