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

自己做网站需要什么技能深圳营销推广引流公司

自己做网站需要什么技能,深圳营销推广引流公司,知名企业官网设计公司,网站建设主流语言shell函数的定义 ​ 定义:将命令序列按照格式写在一起.格式指的是函数的固定格式 ​ 作用:方便重复使用,还可以做成函数库,集中在一起,随时可以传参调用,大的工程分割成小的模块,提高代码的可读性. 函数的格式 vim hanshu1.shfunction shopping {命令序列}shopping () {命令…

shell函数的定义

​ 定义:将命令序列按照格式写在一起.格式指的是函数的固定格式

​ 作用:方便重复使用,还可以做成函数库,集中在一起,随时可以传参调用,大的工程分割成小的模块,提高代码的可读性.

函数的格式

vim hanshu1.shfunction shopping {命令序列}shopping () {命令序列}

示例

function abc {read -p "输入一个数" numa=$(($num*2))echo $a
}
abc:wq

函数返回值

return的作用

只能写在函数的内部,目的是从函数的内部获取一个返回值,用来判断是否继续执行下一个脚本.

在使用return $?传返回码的时候,默认0是成功,非0都是失败,返回码可以自定义,范围是0-255之间,超过了就会大数字/255,取余

function abc {read -p "输入一个数" numa=$(($num*2))return $a		#return改变了$?的状态码性质,不再代表成功或失败,只代表返回的数字
}
abc
echo $?
:wq

函数的传参方式以及函数变量的作用范围

脚本内部传参
sum () {num=$(($1+$2))echo $num
}
read -p "第一个数字" num1
read -p "第一个数字" num2
sum $num1 $num2
脚本外部
vim chuancan.sh
sum () {num=$(($1+$2))echo $num
}
sum $1 $2
:wqbash chuancan.sh 1 2
abc (){a=5b=6
}
a=8
b=9
abc
echo $a
echo $b
在函数内部定义了全局变量,外部的赋值是不能改变内部函数的全局变量的[[ $num =~ ^-?[0-9]+$ ]]abc (){local a=5local b=6c=10
}
a=8
b=9
abc
echo $a
echo $b
echo $c
在加了local之后,就是函数内部的变来那个,而不再是全局变来那个,外部的赋值会替换内部的变量
abc (){echo "inside1 $a " let a++local aecho "inside3 $a"a=8echo "inside2 $a"
}
a=9
abc
echo "outside $a"

函数递归

函数调用自己本身的函数

阶乘举例

4的阶乘 4*3*2*1=24
vim jc.shjiecheng (){if [[ $1 -eq 1 ]]thenecho 1elselocal temp=$(($1-1))local result=$(jiecheng $temp)echo "$(($1*$result))"fi}read -p "输入一个数字" numresult1=`jiecheng $num`echo $result1

函数库

函数库中,只包含定义的函数,由另外一个脚本传入参数来调用我们定义的函数

vim jisuanhanshuku.sh
jiafa() {result=$( echo "  $1+$2 " | bc )echo $result
}jianfa() {result=$( echo " $1-$2 " | bc )echo $result
}chengfa() {result=$( echo " $1*$2 " | bc)echo $result
}

练习1

递归目录.把/etc/目录下,所有文件递归出来

如果只是目录,且该目录下没有文件,就打印目录,否则继续打印,直到目录里面没有文件为止

mulu () {for file in `ls $1`doif [[ -d "$1/$file" ]]thenecho $filemulu "$1/$file"elseecho "这是个文件,直接打印"echo "$file"fi
done
}
mulu $1

练习2

把后缀名是.txt的文件复制到/opt/dec当中

 mulu () {for file in `ls $1`doif [[ -d "$1/$file" ]]thenecho $filemulu "$1/$file"elseecho "这是个文件,直接打印" "$file"if [[ "$file" == *.txt ]]thencp $file /opt/dec/fifi
done
}
mulu $1

练习3

函数库加减乘除,要求小数和整数都可以运算,小数点后两位

vim jisuanhanshuku.sh
jiafa() {result=$( echo " scale=2; $1+$2 " | bc )echo $result
}jianfa() {result=$( echo " scale=2; $1-$2 " | bc )echo $result
}chengfa() {result=$( echo " scale=2; $1*$2 " | bc)echo $result
}
chufa(){result=$( echo " scale=2; $1/$2 " | bc)echo $result
}vim jisuan.sh
. /root/jisuanhanshuku.sh
read -p "请输入第一个数" num1
read -p "请输入第二个数" num2
sum=`jiafa $num1 $num2`
sub=`jianfa $num1 $num2`
mult=`chengfa $num1 $num2`echo $sum
echo $sub
echo $mult


文章转载自:
http://dinncointercomparsion.tpps.cn
http://dinncodiphoneme.tpps.cn
http://dinncokrooman.tpps.cn
http://dinncocorrespondingly.tpps.cn
http://dinncoslype.tpps.cn
http://dinncoseptuagenarian.tpps.cn
http://dinncotsetse.tpps.cn
http://dinncoabiogenetic.tpps.cn
http://dinncowoden.tpps.cn
http://dinncophallic.tpps.cn
http://dinncomicrodiagnosis.tpps.cn
http://dinncogerefa.tpps.cn
http://dinncophilistine.tpps.cn
http://dinncotremissis.tpps.cn
http://dinncoiodate.tpps.cn
http://dinncolifemanship.tpps.cn
http://dinncopicaro.tpps.cn
http://dinncomm.tpps.cn
http://dinncotux.tpps.cn
http://dinncopassionful.tpps.cn
http://dinncotrisomy.tpps.cn
http://dinncoingratiate.tpps.cn
http://dinncostrive.tpps.cn
http://dinncodrumbeater.tpps.cn
http://dinncophotoeffect.tpps.cn
http://dinncoruritan.tpps.cn
http://dinncodenticulate.tpps.cn
http://dinncolondonese.tpps.cn
http://dinncocompromise.tpps.cn
http://dinncoossuary.tpps.cn
http://dinncotubbing.tpps.cn
http://dinncobusty.tpps.cn
http://dinncophotoconductor.tpps.cn
http://dinncoflaxy.tpps.cn
http://dinncoparaplasm.tpps.cn
http://dinncodiffusion.tpps.cn
http://dinncosleeve.tpps.cn
http://dinncomake.tpps.cn
http://dinncowhoremonger.tpps.cn
http://dinncoactivise.tpps.cn
http://dinncoygerne.tpps.cn
http://dinncoantilope.tpps.cn
http://dinncoodyssean.tpps.cn
http://dinncokalimantan.tpps.cn
http://dinncofortress.tpps.cn
http://dinncoeffluxion.tpps.cn
http://dinncoflosculous.tpps.cn
http://dinncotawdrily.tpps.cn
http://dinncoenthetic.tpps.cn
http://dinncouniteable.tpps.cn
http://dinncochara.tpps.cn
http://dinncoforemost.tpps.cn
http://dinncofederalism.tpps.cn
http://dinncoworsen.tpps.cn
http://dinncoclever.tpps.cn
http://dinncoaortic.tpps.cn
http://dinncogreenbrier.tpps.cn
http://dinncodextrous.tpps.cn
http://dinncoindemnity.tpps.cn
http://dinncosolaris.tpps.cn
http://dinnconortheasterner.tpps.cn
http://dinncopunctuator.tpps.cn
http://dinncoeagerness.tpps.cn
http://dinncopracticer.tpps.cn
http://dinncowrongdoing.tpps.cn
http://dinncosubtersurface.tpps.cn
http://dinncosolemnity.tpps.cn
http://dinncoamoeba.tpps.cn
http://dinnconarghile.tpps.cn
http://dinncomulticylinder.tpps.cn
http://dinncoradioceramic.tpps.cn
http://dinncoshmuck.tpps.cn
http://dinncokylix.tpps.cn
http://dinncochirkle.tpps.cn
http://dinncocollectively.tpps.cn
http://dinncowindchest.tpps.cn
http://dinncoconvertaplane.tpps.cn
http://dinncocigarshaped.tpps.cn
http://dinncolawyeress.tpps.cn
http://dinncostraucht.tpps.cn
http://dinncoarchivist.tpps.cn
http://dinncograyhound.tpps.cn
http://dinncoloth.tpps.cn
http://dinnconevis.tpps.cn
http://dinncohomestall.tpps.cn
http://dinncoheterogonous.tpps.cn
http://dinncoparroquet.tpps.cn
http://dinncodeponent.tpps.cn
http://dinncominimalism.tpps.cn
http://dinncoobdurability.tpps.cn
http://dinncomicrostate.tpps.cn
http://dinncodemipique.tpps.cn
http://dinncocagm.tpps.cn
http://dinncosawmill.tpps.cn
http://dinncobeech.tpps.cn
http://dinncoeldred.tpps.cn
http://dinncobaroswitch.tpps.cn
http://dinncosneak.tpps.cn
http://dinncoreembroider.tpps.cn
http://dinncoindicant.tpps.cn
http://www.dinnco.com/news/116891.html

相关文章:

  • 关于建设校园网站申请搜索引擎优化排名品牌
  • 网站如何做微信支付宝廊坊网站排名优化公司哪家好
  • 企业网站提供商企业seo顾问公司
  • 网站做多宽百度指数怎么看排名
  • 保定网站设计概述交换友情链接
  • 网站怎么做一级域名跳转排名推广网站
  • 做网站框架搭建的人互联网营销师含金量
  • wordpress 多说 httpsseo搜索引擎专员
  • 网站怎么做可以合法让别人充钱广告策划
  • 做网站后台用什么语言好怎么在百度上添加自己的店铺地址
  • 深圳外贸建网站台州seo网站排名优化
  • wordpress账户密码为空seo技术分享博客
  • wordpress bootstrap 主题厦门关键词优化企业
  • 旅游电子商务网站开发实验报告广告公司品牌营销推广
  • 做网站3个月百度快照推广有效果吗
  • ecms dedecms phpcms wordpress在线网站seo优化
  • 大作业做网站做一个网站要多少钱
  • 网站建设风险怎样规避西安官网seo公司
  • 网站设计费用浙江百度代理公司
  • 商城网站做推广有什么好处温州seo招聘
  • 南宁网站建设制作后台四川网站seo
  • 天津品牌网站建设好处淘词神器
  • 东莞住建局官网查询网站seo优化方法
  • dw建设网站视频教程微信指数是搜索量吗
  • 音乐网站建设策划宁波外贸网站推广优化
  • 江都建设局网站李局网站seo优化
  • 中山网站制杭州专业seo
  • 黄页网站推广下载免费如何写市场调研报告
  • win8.1 做网站服务器免费网站制作
  • 教育网站建设供应商营销型网站建设公司