CompTIA Linux+ XK0-005 Practice Question
A system administrator needs to write a shell script that prompts the user for a file name and then reads a single line from that file. The goal is to store this line in a variable for further processing. Which of the following options achieves this while making sure the script asks for the file name and reads only the first line of the provided file?
read -p "Enter the file name: " file; line=$(cat $file | head -n 1)
read -p "Enter the file name: " file; IFS= read -r line <<< "$file"
read -p "Enter the file name: " file; IFS= read -r line <<< $(cat $file)
read -p "Enter the file name: " file; IFS= read -r line < "$file"