Reality Check (week 3) Solutions: Question #1: #!/bin/bash read -p "Please enter pathname to search: " dirPathName cd $dirPathName 2> /dev/null && (echo "Directory pathname $dirPathName is valid, please proceed...";read -p "Please enter a search pattern: " searchPattern; echo; echo "Here are files that contain the pattern $searchPattern"; grep -in $searchPattern $dirPathName/*;echo) || { echo "Pathname $dirPathName is not valid. Please run again...">&2;exit 2;} echo "Task completed..." Question #2: #!/bin/bash read -p "Please enter pathname to search: " dirPathName cd $dirPathName 2> /dev/null && (echo "Directory pathname $dirPathName is valid, please proceed...";read -p "Please enter a search pattern: " searchPattern; echo; echo "Here are files that contain the pattern $searchPattern"; grep -in $searchPattern $dirPathName/*;echo) || { echo "Pathname $dirPathName is not valid. Please run again...">&2;exit 2;} read -p "Do you want me to list contents of these files? (Y|N):" answer if echo $answer | grep -iq y then cat $(grep -in $searchPattern $dirPathName/*) fi echo "Task completed..." Question #3: #!/bin/bash read -p "Please enter pathname to search: " dirPathName cd $dirPathName 2> /dev/null && (echo "Directory pathname \"$dirPathName\" is valid, please proceed...";read -p "Please enter a search pattern: " searchPattern; echo; echo "Here are files that contain the pattern \"$searchPattern\""; grep -in $searchPattern $dirPathName/*;echo) || { echo "Pathname \"$dirPathName\" is not valid. Please run again...">&2;exit 2;} read -p "Do you want me to list contents of these files? (Y|N):" answer if echo $answer | grep -iq y then cat $(grep -in $searchPattern $dirPathName/*) fi echo "Task completed..."