#!/bin/bash
x=0
# =
if [ "$x" -eq 0 ];
then
x=1;
echo "$x"
fi
while [ "$x" -lt 10 ];
do
y="$x"
echo "$x"
x=`expr $x + 1`
done
#使用while 读取文件解析每行数据并赋予变量
test.sh
#!/bin/bash
while read id name age
do
echo "id:${id} name:${name} age:${age}"
done < ./data
#数据文件如下:
1 zhangsan 50
2 lishi 30
执行sh test.sh 输出如下:
id:1 name:zhangsan age:50
id:2 name:lishi age:30