42
Use this (it is loop of reading each line from file file)
使用它(它是從文件文件中讀取每一行的循環)
cat file | while read -r a; do echo $a; done
where the echo $a is whatever you want to do with current line.
echo $ a是你想用當前行做什么的。
UPDATE: from commentators (thanks!)
更新:來自評論員(謝謝!)
If you have no file with multiple lines, but have a variable with multiple lines, use
如果沒有多行文件,但有多行變量,請使用
echo "$variable" | while read -r a; do echo $a; done
UPDATE2: "read -r" is recommended to disable backslashed (\) chars interpretation (check mtraceur comments; supported in most shells). It is documented in POSIX 1003.1-2008 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html
UPDATE2:建議使用“read -r”來禁用反斜杠(\)字符解釋(檢查mtraceur注釋;在大多數shell中都支持)。它在POSIX 1003.1-2008中有記錄http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html
By default, unless the -r option is specified, shall act as an escape character. .. The following option is supported: -r - Do not treat a character in any special way. Consider each to be part of the input line.
默認情況下,除非指定了-r選項,否則
將充當轉義字符。 ..支持以下選項:-r - 不要以任何特殊方式處理 字符。考慮每個都是輸入行的一部分。