Shell while read row
The difference between for i in cat file and while read line
#! / bin/bash#Auth: andy#Date: 20191114#Describe: statistics word_file= ". / cui" # will take the words of each line as the output of each new line # for i in `cat. / cui`; do# l = `echo $I | wc-L` # echo ${l} # if [${l}-gt 6] The word then# echo $i# fi#done## is still in the line a=0while read linedo axiom $[aq1] echo "line ${a} content" for i in $line; do l = `echo $I | wc-L` if [${l}-gt 6]; then echo-n $i fi done echo done <. / cui
While reads are based on the shell read separator
While IFS is a set variable, when shell handles "command substitution" and "parameter substitution", shell disassembles the interpreted variable according to the value of IFS, default is space, tab, and newline, then processes the special characters, and finally reassembles the assignment to the variable.
The direct output of IFS is not visible, so you can see it by converting it to binary. "040s" is a space, "011s" is Tab, and "012s" is a newline character "\ n". The last 012 is because echo breaks lines by default. Change IFS
$cat 1.txt
1,a
2,b
3,c
4,d
$cat test.sh
Use comma division