In: Computer Science
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url.
The shell script should then retrieve the file associated with the
URL by using the curl command.
The output of the curl command should be
redirected to a file named
html_file.
The shell script should then use the grep command to search the file named html_file for the word manhattan.
Finally, the shell script should make the file named
html_file readable to everyone by issuing the
appropriate chmod command to give "o" (others)
read permission on the file.
Please find the requested script below. Also including the screenshot of sample output
Please provide your feedback
Thanks and Happy learning!
#!/bin/bash
#Above line sets the environment for the script to bash
#Check for the command line argument
if [ $# -eq 1 ]
then
url="$1"
else
echo "There should be exactly one command line argument."
exit 0;
fi
#retrieve the file associated with the URL by using the curl command to file html_file
#syntax of the curl command to get the url to an output file is as follows
#curl http://some.url --output some.file
`curl $url --output html_file`
#use the grep command to search the file named html_file for the word manhattan.
grep "manhattan" html_file
#make the file named html_file readable to everyone by issuing the appropriate chmod command
#to give "o" (others) read permission on the file.
chmod o+r html_file