码迷,mamicode.com
首页 > 系统相关 > 详细

Shell 编程(二)

时间:2018-05-05 14:16:24      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:lines   pass   nes   color   home   ubunt   .sh   循环   roc   

for in 循环语句

#!/bin/bash
for x in one two three four
do
        echo number $x
done

例:取出passwd中每一行name 并输出 hello + name

#!/bin/bash
LINES=`wc -l /home/eko/passwd | cut -d‘ ‘ -f1`
for i in `seq 1 $LINES`
do
        echo "hello,`head -n $i /home/eko/passwd | tail -n 1 | cut -d: -f1`"
done

* seq 语句 

root@ubuntu:/home/eko# seq 1 5
1
2
3
4
5

root@ubuntu:/home/eko# seq 1 2 10
1
3
5
7
9

 for 循环

#!/bin/bash
for((i=1;i<10;i++))
do
echo "hello $i"
done

 for file in

#!/bin/bash  
  
for file in /proc/*;  
do  
echo $file is file path \! ;  
done   


#!/bin/bash  
  
for file in $(ls *.sh)  
do  
echo $file is file path \! ;  
done  

 

while

while [ $count -le 6 ]; do
    echo $count
    count=$((count + 1))
done
echo "finished"

 

Shell 编程(二)

标签:lines   pass   nes   color   home   ubunt   .sh   循环   roc   

原文地址:https://www.cnblogs.com/xiaoliwang/p/8988711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!