Linuxwilliam hill官网
直播中

慧心的眼眸

6年用户 631经验值
私信 关注
[经验]

Linux Shell系列教程之Shell for循环

  Shell for循环语法
  Shell for循环的语法如下所示
  for 变量 in 列表
  do
  command1
  command2
  ...
  commandN
  done
  列表是一组值(数字、字符串等)组成的序列,每个值通过空格分隔。每循环一次,就将列表中的值依序放入指定的变量中,然后重复执行命令区域(在do和done 之间),直到所有元素取尽为止。
  Shell for循环示例
  接下来通过示例的方式给大家介绍下Shell for循环的用法。
  for loop in one two tree four
  do
  echo "I am : $loop"
  done
  输出结果:
  I am : one
  I am : two
  I am : tree
  I am : four
  可以顺序输出字符串的单词,示例:
  for str in I am chuangkexeuyuan
  do
  echo $str
  done
  输出结果:
  I
  am
  linuxdaxue
  可以显示当前目录下的文件,示例:
  for file in ./*
  do
  echo $file
  done
  输出结果:
  ./a.sh
  ./automake
  ./automonitor
  ./crzk
  ./makedir
  ./shell_start
  ./sql
  ./subm
  linux学习交流群:690327559

更多回帖

发帖
×
20
完善资料,
赚取积分