Automation, Orchestration, and Scripting
A line of input has three leading spaces and three trailing spaces around its text. Which command stores the line in the variable line with those spaces kept?
Show the answer
Correct answerB. IFS= read -r line
AWhy not this: -r only stops backslash interpretation; the default IFS still trims the leading and trailing spaces.
BWhy this is right: An empty IFS stops read from trimming whitespace, and -r keeps backslashes literal.
CWhy not this: With the default IFS, read strips leading and trailing spaces and tabs from the line.
DWhy not this: IFS set to a space still makes read trim leading and trailing spaces.
With IFS set to an empty string, read performs no field splitting and does not trim whitespace. With the default IFS, leading and trailing spaces and tabs are stripped. The -r option only stops backslash interpretation and has no effect on trimming.