Find out the difference between for and while, and write out the memo.
Script:
File =/home/hadoop/phrases.txt for content in 'cat $ {file} 'Do phrase = 'echo $ {content}' echo $ phrasedone
The phrases.txt file contains the following content:
Hello previous rep
Naturally, the echo $ phrase value is "Hello previous Rep", but unexpectedly, the result is "hello ". How can I print the entire line "Hello previous Rep? Use while.
File =/home/hadoop/phrases.txt cat $ {file} | while read contentdo phrase = 'echo $ {content} 'echo $ phrasedone
Print the result: "Hello previous rep.
Cause: the for loop uses space as the separator, while uses a line as the separator. Therefore, if a line of text contains spaces, it is best to use while to traverse multiple lines of text.
If it is reprinted, please explain the source! Http://blog.csdn.net/xukunddp