CompTIA Study Materials
AWS Study Materials
AWS Certified Developer Associate AWS Certified Developer Associate
AWS Certified Developer Associate DVA-C02
AWS Certified Solutions Architect Associate AWS Certified Solutions Architect Associate
AWS Certified Solutions Architect Associate SAA-C03
AWS Cloud Practitioner AWS Cloud Practitioner
AWS Cloud Practitioner CLF-C02
Microsoft Study Materials
Microsoft Azure Fundamentals Microsoft Azure Fundamentals
Microsoft Azure Fundamentals AZ-900

Free 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; IFS= read -r line <<< $(cat $file)

  • read -p "Enter the file name: " file; IFS= read -r line < "$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"

This question is for objective:
Scripting, Containers, and Automation
Your Score:
Scripting, Containers, and Automation
System Management
Security
Troubleshooting
SAVE $45