zoukankan      html  css  js  c++  java
  • linux for 命令常用的读写方法

    1、标准方式:

      for var in list
      do
        commands
      done
     
    2、一行书写方式:
      for var in list; do
     
    3、读取列表中的值
      for test in Nevada New Hampshire New Mexico New York North Carolina
      do
        echo "Now going to $test"
      done
     
    4、从变量读取列表
    list="Alabama Alaska Arizona Arkansas Colorado"
    list=$list" Connecticut" 
    for state in $list
    do
      echo "Have you ever visited $state?"
    done
    $ ./test4
    Have you ever visited Alabama?
    Have you ever visited Alaska?
     
    5、从命令读取值
    file="states"
    for state in $(cat $file)
    do
      echo "Visit beautiful $state"
    done
    $ cat states
    Alabama
    Alaska
    Arizona
    $ ./test5
    Visit beautiful Alabama
    Visit beautiful Alaska
    Visit beautiful Arizona
     
    6、在bash shell C 语言的 for 命令
    for (( i=1; i <= 10; i++ ))
    do
      echo "The next number is $i"
    done
    The next number is 1
    The next number is 2
    The next number is 3
    7、bash shell C 语言的 for 命令,使用多个变量
    for (( a=1, b=10; a <= 10; a++, b-- ))
    do
      echo "$a - $b"
    done
    1 - 10
    2 - 9
    3 - 8
  • 相关阅读:
    闭包
    iframe
    函数声明和函数表达式
    简单的事件委托
    onhashchange
    WebP探索
    Chrome
    适合自己学习的一些网站
    模拟jQuery的一些功能
    __autoload()方法
  • 原文地址:https://www.cnblogs.com/z977690557/p/13903025.html
Copyright © 2011-2022 走看看