Shell作用是解释执行用户的命令,用户输入一条命令,Shell就解释执行这一条,这种方式称为交互式,但还有另一种执行命令的方式称为批处理方式,用户事先写一个Shell脚本,Shell可以一次把这些命令执行完. 如下例子: #!/bin/bashecho "this is a test"cd ..ls Shell脚本中⽤用#表⽰示注释,相当于C语⾔言的//注释.但如果#位于第⼀一⾏行开头,并且是则例外,它表⽰示该脚本使⽤用后⾯面指定的解释器/bin/sh解释执⾏行.如果把这个脚本⽂文件…
写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do myfun count=$[ $count +1 ] done echo "This is the end of the loop" myfun ech…
使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do myfun count=$[ $count +1 ] done echo "This is the end of the loop" myfun echo "Now this is the end…
Shell 也支持函数.Shell函数必须先定义后使用. 函数的定义与调用 Shell 函数的定义格式如下: function_name () { list of commands [ return value ] } 函数返回值,可以显式增加return语句:如果不加,会将最后一条命令运行结果作为返回值. 调用函数只需要给出函数名,不需要加括号.下面给出Shell函数定义和调用的一个简单例子: #!/bin/bash # Define your function here Hello () {…