`

shell-while-for

阅读更多
while 循环

1、基本用法:
#!/bin/bash
source /etc/profile

while read dataline
do 
  echo "$dataline"
done



2、循环读入一个文件。
方式1:
#!/bin/bash
source /etc/profile

cat $*|
while read dataline
do 
  echo "$dataline"
done


方式2:
#!/bin/bash
source /etc/profile

filename=$1
if [ ! -r "$filename" ];then
   echo "can not read $filename"
   exit 1
fi

while read dataline
do 
  echo "$dataline"
done < $filename



3、while 循环输出内容到一个文件。
#!/bin/bash
source /etc/profile

filename=$1
if [ ! -r "$filename" ];then
   echo "can not read $filename"
   exit 1
fi

while read dataline
do 
  echo "$dataline"
done < $filename >output.data


4、命令行执行for
for i in `cat num2.txt` ;do echo $i; done |awk 'BEGIN {a=0} {a+=$1} END {print a}' 
分享到:
评论

相关推荐

    【IT十八掌徐培成】Linux第02天-05.if-for-while-参数处理-shell编程.zip

    【IT十八掌徐培成】Linux第02天-05.if-for-while-参数处理-shell编程.zip

    linux-Shell编程视频教程

    11.1 Shell编程-正则表达式.mp4 11.2.1 Shell编程-字符截取命令-cut命令.mp4 11.2.2 Shell编程-字符截取命令-printf命令.mp4 11.2.3 Shell编程-字符截取命令-...11.5.4 Shell编程-流程控制-while循环与until循环.mp4

    shell编程—-while和until循环

      while循环是shell脚本中最简单的一种循环,当条件满足时,while重复地执行一组语句;当条件不满足时,就退出while循环。 shell while循环的用法如下: while condition do statements done   condition表示...

    【shell脚本】shell脚本之条件判断if、for与while循环(shell脚本基础学习二)

    【shell脚本】shell脚本之条件判断if、for与while循环(shell脚本基础学习二) shell中的if 单分支 if 条件测试 ;then 命令序列 fi 双分支 if 条件测试 ;then 命令序列1 else 命令序列2 fi 多分支 if 条件测试 ;...

    shell for&while; 循环详细总结

    shell for&while; 循环详细总结 详细描述了 for while 循环 可用的七八种情况,本人都以测试通过

    linuxSHELL学习之for、while、until

    linuxSHELL学习之for、while、until

    linux 下Shell编程各个知识点举例

    case.sh guess_data.sh nfs_install.sh shell-base.sh while.sh data_cmp.sh homework-3.sh ping.sh shell-test.sh file_compare.sh huzl.sh pskill.sh test file_judge.sh if.sh read-file.sh test.c

    linux shell循环:for、while、until用法详解

    主要介绍了linux shell下常用的循环for、while、until的用法,这也是脚本之家小编看到的比较详细的文章了,感兴趣的朋友可以参考一下,最好是在环境下自己手工打一份,不要复制

    Linux Shell Scripting Cookbook - Third Edition

    Intermediate / advanced users, system administrators / developers, and programmers can use this book as a reference when they face problems while coding. What You Will Learn Interact with websites ...

    Shell编程中while与for的区别及用法详解

    在shell编程中经常用到循环,常用的循环有for和while循环两种。while循环默认以行读取文件,而for循环以空格读取文件切分文件,本篇就结合现网的一些使用示例说说二者的用法和区别。 一、常用语法 1、for循环 for...

    Shell中的for和while循环详细总结

    主要介绍了Shell中的for和while循环详细总结,本文讲解了for循环的数字段形式、详细列出、对文件进行循环,while循环的三种使用场合等内容,需要的朋友可以参考下

    Linux简明教程.rar

    5.3 while语句 5.4 until语句 5.5 break和continue命令 5.6 case语句 6. 常用命令集锦 六、shell后台运行程序----------------------------------------------------------------------------- 编辑器的使用--...

    PHP代码美化 格式化 反格式化

    --space-after-if --optimize-eol --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --extra-padding-for-case-statement --glue-amperscore --...

    shell教程-30章,下了之后会让你大吃一惊,相当好

    第一部分 shell 第1章 文件安全与权限 1 1.1 文件 1 1.2 文件类型 2 1.3 权限 2 1.4 改变权限位 4 1.4.1 符号模式 4 1.4.2 chmod命令举例 5 1.4.3 绝对模式 5 1.4.4 chmod命令的其他例子 6 1.4.5 可以选择使用符号...

    第二十三章:shell循环之for、while、case.pdf

    第二十三章:shell循环之for、while、case.pdf

    Shell脚本常识--(循环控制)

    了解并掌握shell中的while循环和for循环的语法格式及其应用。

    shell高级编程实例(365例子)

    Shell脚本高级编程教程,希望对你有所帮助。 Example 10-23. Using continue N in an actual task: 1 # Albert Reiner gives an example of how to use "continue N": 2 # -------------------------------------...

    shell浅谈之三for、while、until循环

    Shell编程中循环命令用于特定条件下决定某些语句重复执行的控制方式,有三种常用的循环语句:for、while和until。while循环和for循环属于“当型循环”,而until属于“直到型循环”。循环控制符:break和continue控制...

    Shell课程视频.zip

    16Shell For1案例.mp4 17Shell For2案例.mp4 18Shell While案例.mp4 19Shell Read案例.mp4 20Shell BaseName&DirName案例.mp4 21Shell 自定义函数案例.mp4 22Shell Cut案例.mp4 23Shell Sed案例.mp4 ..........

Global site tag (gtag.js) - Google Analytics