Bash 逐行读取与嵌套循环笔记
Linux
阅读时长: 1 分钟
shell readline for
1
2
3
4
|
while read -r line;
do
echo "$line" ;
done < input.file
|
1
2
3
|
while read x; do echo $x; done << EOF
$(ls -l $1)
EOF
|
1
2
|
ls -l $1 | while read x; do echo $x; done
ls | while read line;do echo "/data/path/start.sh";done
|
1
2
3
|
IFS='
'
for x in `ls -l $1`; do echo $x; done
|
不改变当前shell的IFS;Put a sub-shell around it if you don’t want to set IFS permanently:
1
2
3
|
(IFS='
'
for x in `ls -l $1`; do echo $x; done)
|
嵌套循环
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/bash
#set -x
cd /data/app
while read -r line;
do
if [ ! -d $line ]
then
echo "$line not exist"
fi ;
done < /tmp/applist
|