当前位置: 首页 > news >正文

垂直网站做益智类问答教务管理系统设计

垂直网站做益智类问答,教务管理系统设计,自己公司做网站,月季花app是哪家公司开发的1. for命令 下面是bash shell中for命令的基本格式。 for var in list docommands done每次for命令遍历值列表,它都会将列表中的下个值赋给$test变量。$test变量可以像for 命令语句中的其他脚本变量一样使用。在最后一次迭代后,$test变量的值会在shell脚…

1. for命令

下面是bash shell中for命令的基本格式。

for var in list docommands
done

每次for命令遍历值列表,它都会将列表中的下个值赋给$test变量。$test变量可以像for 命令语句中的其他脚本变量一样使用。在最后一次迭代后,$test变量的值会在shell脚本的剩余 部分一直保持有效。它会一直保持最后一次迭代的值(除非你修改了它)。

$ cat for_test.sh
#!/bin/bash
for test in Alabama Alaska Arizona Arkansas California
doecho The text next state is $test
done
echo "The last state we visited was $test"
test=hello
echo "Wait, now we're visiting $test"$ bash for_test.sh
The text next state is Alabama
The text next state is Alaska
The text next state is Arizona
The text next state is Arkansas
The text next state is California
The last state we visited was California
Wait, now we're visiting hello

从变量中读取值

#!/bin/bash 13
# using a variable to hold the list
list="Alabama Alaska Arizona Arkansas Colorado"
list=$list" Connecticutfor state in $list
doecho "Have you ever visited $state?"
done

从命令中读取

$ cat test5
#!/bin/bash
# reading values from a file
file="states"
for state in $(cat $file)
doecho "Visit beautiful $state"
done

更改字段分隔符

特殊的环境变量IFS,叫作内部字段分隔符(internal field separator)IFS环境变量定义了bash shell用作字段分隔符的一系列字符。默认情况下,bash shell会将下列字 符当作字段分隔符:

  • 空格
  • 制表符
  • 换行符

可以在shell脚本中临时更改IFS环境变量的值来限制被bash shell当作字段 分隔符的字符。

IFS=$'\n'

用通配符读取目录

$ cat test6
#!/bin/bash
for file in /home/rich/test/*
doif [ -d "$file" ]thenecho "$file is a directory"elif [ -f "$file" ]thenecho "$file is a file"fi
done
$ ./test6
/home/rich/test/dir1 is a directory
/home/rich/test/myprog.c is a file
/home/rich/test/myprog is a file
/home/rich/test/myscript is a file
/home/rich/test/newdir is a directory
/home/rich/test/newfile is a file
/home/rich/test/newfile2 is a file
/home/rich/test/testdir is a directory
/home/rich/test/testing is a file
/home/rich/test/testprog is a file
/home/rich/test/testprog.c is a file

1.1 类C语言for语句

C语言风格的for命令看起来如下

for (( a = 1; a < 10; a++ )) 

注意,有些部分并没有遵循bash shell标准的for命令:

  • 变量赋值可以有空格;
  • 条件中的变量不以美元符开头;
  • 迭代过程的算式未用expr命令格式。

以下例子是在bash shell程序中使用C语言风格的for命令。

$ cat test8
#!/bin/bash
# testing the C-style for loop
for (( i=1; i <= 10; i++ ))
doecho "The next number is $i"
done
$ ./test8
The next number is 1
The next number is 2
The next number is 3
The next number is 4
The next number is 5
The next number is 6
The next number is 7
The next number is 8
The next number is 9
The next number is 10
$

2. while命令

while命令的格式是:

while testcommand doother commands
done

while命令的关键在于所指定的test command的退出状态码必须随着循环中运行的命令而
改变。如果退出状态码不发生变化, while循环就将一直不停地进行下去。

最常见的test command的用法是用方括号来检查循环命令中用到的shell变量的值。

$ cat test10
#!/bin/bash
# while command test
var1=10
while [ $var1 -gt 0 ]
do
echo $var1var1=$[ $var1 - 1 ]
done
$ ./test10
10
9
8
7 
6 
5
4 
3 
2 
1 
$
http://www.yayakq.cn/news/532868/

相关文章:

  • 荆门做微信公众号的网站哪些网站不能备案
  • 做网站找公司怎么找html网页制作免费模板下载
  • 阿里云做的海外网站怎么样做网站必须知道的问题
  • 公司网站开发视频怎样在赶集微网站做微招聘
  • 传统小型企业做网站的好处简述建设一个商务网站的过程
  • 做黄金的网站婚庆公司服务内容
  • 工信部网站icp备案查询如何做好网站宣传
  • 做个人网站深圳做棋牌网站建设
  • 手机网站设计字体多大深圳市建网站公
  • 简述搜索引擎的工作原理网站上的产品五星怎样做优化
  • 网站开发的图片要求淘宝客高佣金网站建设
  • 西安做网站魔盒培训体系搭建
  • 网站建设的流程该怎么确定wordpress 打开速度慢
  • 芜湖网站建设芜湖菲纳斯wordpress
  • 网站开发工程师 北大青鸟网站怎么做配置文件夹
  • 电子商务网站网站建设社交网站开发
  • 上海网站seo优化分享公众号的网站
  • 厦门网站设计哪家公司好购物网站建设思维导图
  • 中山网站软件马云做一网站 只作一次
  • 青岛专业网站建设公司排名电商运营要学多久
  • 用护卫神做网站许昌网站推广公司
  • 制作网站建设网站建设基础教程
  • 一般做企业网站多少钱关于建设官方网站的申请
  • 深圳营销建网站公司手机触屏网站
  • 赣州住房与城乡建设厅网站宁波北仑装修公司排行
  • 威海网站seo微信网页宣传网站怎么做
  • 婚庆网站策划书百度网络营销中心app
  • 网站设计实用实例搭建网站需要哪些步骤
  • 怎么在网站上添加qq138ip查询网域名解析
  • 公司网站建设的重要性酒店用品网站源码