脚本小练习
MacBook-Pro-8:shelltest baidu$ cat student_info.txt
John 30 Boy
Sue 28 Girl
Wang 25 Boy
Xu 23 girl
MacBook-Pro-8:shelltest baidu$ cat student_while.sh
while read line
do
name=`echo $line | awk '{print $1 }'`
age=`echo $line |awk '{ print $2 }'`
sex=`echo $line |awk ' {print $3}'`
echo $name,$age,$sex
done < student_info.txt
MacBook-Pro-8:shelltest baidu$ cat student_while.sh | sh
John,30,Boy
Sue,28,Girl
Wang,25,Boy
Xu,23,girl
MacBook-Pro-8:shelltest baidu$ cat student_while1.sh
while read line; do name=`echo $line | awk '{print $1 }'` &&age=`echo $line |awk '{ print $2 }'`&& sex=`echo $line |awk ' {print $3}'`&& echo $name,$age,$sex; done < student_info.txt
MacBook-Pro-8:shelltest baidu$ cat student_while1.sh | sh
John,30,Boy
Sue,28,Girl
Wang,25,Boy
Xu,23,girl
MacBook-Pro-8:shelltest baidu$
- 点赞
- 收藏
- 关注作者
评论(0)