• 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
  • 相关阅读:
    2-SAT·hihoCoder音乐节
    Music in Car
    Game with a Strip
    Oleg and Little Ponies
    组合数性质求K个数选取i*j个数分成j组的方案数
    Python学习笔记03
    Python学习笔记02
    Python 学习笔记01
    欺骗侦测
    Oracle 使用小计(4)
  • 原文地址:https://www.cnblogs.com/z977690557/p/13903025.html
Copyright © 2020-2023  润新知