中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

html5建設(shè)攝影網(wǎng)站意義銷售管理怎么帶團隊

html5建設(shè)攝影網(wǎng)站意義,銷售管理怎么帶團隊,域名訪問網(wǎng)站應(yīng)該怎么做,怎么發(fā)現(xiàn)網(wǎng)站漏洞而做軟件概念 函數(shù)就是將你需要執(zhí)行的shell命令組合起來,組成一個函數(shù)體。一個完整的函數(shù)包括函數(shù)頭和函數(shù)體,其中函數(shù)名就是函數(shù)的名字。 優(yōu)點 將相同的程序,定義,封裝為一個函數(shù),能減少程序的代碼數(shù)量,提高開發(fā)…

概念

函數(shù)就是將你需要執(zhí)行的shell命令組合起來,組成一個函數(shù)體。一個完整的函數(shù)包括函數(shù)頭和函數(shù)體,其中函數(shù)名就是函數(shù)的名字。

優(yōu)點

  • 將相同的程序,定義,封裝為一個函數(shù),能減少程序的代碼數(shù)量,提高開發(fā)效率。
  • 使用函數(shù),能讓你寫更少的代碼,早點寫完,早點回家休息多好。
  • 函數(shù)能夠增加代碼的可讀性,易讀性,容器管理。

函數(shù)的實際開發(fā)

shell函數(shù)定義的語法

# 標準shell函數(shù)定義
function 函數(shù)名() {函數(shù)體你想執(zhí)行的Linux命令return 返回值
}# 偷懶寫法
# 當使用function關(guān)鍵字時候,可以省略括號
function 函數(shù)名 {函數(shù)體你想執(zhí)行的那些命令。。。。return 返回值
}# 超人懶人寫法,shell老司機的時候
# 必須有括號
函數(shù)名() {函數(shù)體代碼。。。return 返回值
}# 執(zhí)行該函數(shù)
函數(shù)名

執(zhí)行函數(shù)的基礎(chǔ)概念

有關(guān)函數(shù)執(zhí)行的基本概念

  • 執(zhí)行shell函數(shù),直接寫函數(shù)名字即可,無需添加其他內(nèi)容
  • 函數(shù)必須先定義,在執(zhí)行,shell腳本自上而下加載
  • 函數(shù)體內(nèi)定義的變量,稱之為局部變量
  • 函數(shù)體內(nèi)需要添加return語句,作用是退出函數(shù),且賦予返回值給調(diào)用該函數(shù)的程序,也就是shell腳本
  • return語句和exit不同
    • return是結(jié)束函數(shù)的執(zhí)行,返回一個(退出值、返回值)
    • exit是結(jié)束shell環(huán)境,返回一個(退出值、返回值)給當前的shell
  • 函數(shù)如果單獨寫入一個文件里,需要用source讀取
  • 函數(shù)內(nèi),使用local關(guān)鍵字,定義局部變量

函數(shù)實踐

場景1:

xiao123@xiao123:~/Downloads/shscripts$ cat ./func1.sh
#! /bin/bashfunction chaochao() {cd /tmpecho "我準備創(chuàng)建一個文件,且寫入信息"echo "愛的魔力轉(zhuǎn)圈圈" > ./music.txtreturn 0
}chaochao
xiao123@xiao123:~/Downloads/shscripts$

運行結(jié)果:

xiao123@xiao123:~/Downloads/shscripts$ bash ./func1.sh
我準備創(chuàng)建一個文件,且寫入信息
xiao123@xiao123:~/Downloads/shscripts$ ls /tmp/
message.txt
music.txt
xiao123@xiao123:~/Downloads/shscripts$
xiao123@xiao123:~/Downloads/shscripts$ cat /tmp/music.txt
愛的魔力轉(zhuǎn)圈圈
xiao123@xiao123:~/Downloads/shscripts$

場景2:
函數(shù)定義和執(zhí)行,分開在不同的文件中,Linux自帶的諸多腳本,都是基于該形式使用的。

  • 函數(shù)寫在一個文件中,只定義,不執(zhí)行
  • 另外一個腳本,讀取該文件,且加載該函數(shù)
1. 先定義一個my_function.c腳本,作用是只記錄函數(shù),不運行
xiao123@xiao123:~/Downloads/shscripts$ cat my_function.sh
#!/bin/bashchao(){echo "我是函數(shù),我被執(zhí)行~你真棒"
}
xiao123@xiao123:~/Downloads/shscripts$2.如何檢查當前的shell環(huán)境變量
xiao123@xiao123:~/Downloads/shscripts$ set | grep ^chao
xiao123@xiao123:~/Downloads/shscripts$3.利用source命令讀取shell腳本,能夠加載其變量到當前shell環(huán)境中
xiao123@xiao123:~/Downloads/shscripts$ source my_function.sh
xiao123@xiao123:~/Downloads/shscripts$4.再次驗證
xiao123@xiao123:~/Downloads/shscripts$ set | grep ^chao
chao ()
xiao123@xiao123:~/Downloads/shscripts$5.可以推出當前shell,再次登錄,查看該環(huán)境變量
exit
xiao123@xiao123:~$ chao
Command 'chao' not found, did you mean:command 'chaos' from deb emboss (6.6.0+dfsg-11ubuntu1)command 'chat' from deb ppp (2.4.9-1+1ubuntu3)
Try: apt install <deb name>
xiao123@xiao123:~$xiao123@xiao123:~/Downloads/shscripts$ source my_function.sh
xiao123@xiao123:~/Downloads/shscripts$ set | grep ^chao
chao ()
xiao123@xiao123:~/Downloads/shscripts$ chao
我是函數(shù),我被執(zhí)行~你真棒
xiao123@xiao123:~/Downloads/shscripts$

使用腳本加載chao,并執(zhí)行

xiao123@xiao123:~/Downloads/shscripts$ cat fun3.sh
#! /bin/bash[ -f ./my_function.sh ] && . my_function.sh || exit -1chao
xiao123@xiao123:~/Downloads/shscripts$xiao123@xiao123:~/Downloads/shscripts$ bash fun3.sh  #啟動子shell,在子shell中加載
我是函數(shù),我被執(zhí)行~你真棒
xiao123@xiao123:~/Downloads/shscripts$xiao123@xiao123:~/Downloads/shscripts$ chao
\Command 'chao' not found, did you mean:command 'chat' from deb ppp (2.4.9-1+1ubuntu3)command 'chaos' from deb emboss (6.6.0+dfsg-11ubuntu1)
Try: apt install <deb name>
xiao123@xiao123:~/Downloads/shscripts$xiao123@xiao123:~/Downloads/shscripts$ source fun3.sh   # 在當前shell中加載
我是函數(shù),我被執(zhí)行~你真棒
xiao123@xiao123:~/Downloads/shscripts$ set | grep ^chao
chao ()
xiao123@xiao123:~/Downloads/shscripts$ chao
我是函數(shù),我被執(zhí)行~你真棒
xiao123@xiao123:~/Downloads/shscripts$

bash 開啟子shell執(zhí)行,source使用當前shell執(zhí)行

函數(shù)處理參數(shù)

函數(shù)可以處理來自命令行傳到shell腳本中的參數(shù)。

my_function.sh

xiao123@xiao123:~/Downloads/shscripts$ cat my_function.sh
#!/bin/bashchao(){echo "我是函數(shù),我被執(zhí)行~你真棒"
}helloPyyu(){echo "兄臺,你傳入的腳本參數(shù),依次是 $1 $2 $3,并且參數(shù)個數(shù)一共是$#"
}
xiao123@xiao123:~/Downloads/shscripts$

fun3.sh

xiao123@xiao123:~/Downloads/shscripts$ cat fun3.sh
#! /bin/bash[ -f ./my_function.sh ] && . my_function.sh || exit -1helloPyyu $1 $2 $3
xiao123@xiao123:~/Downloads/shscripts$

運行結(jié)果

xiao123@xiao123:~/Downloads/shscripts$ bash fun3.sh
兄臺,你傳入的腳本參數(shù),依次是   ,并且參數(shù)個數(shù)一共是0
xiao123@xiao123:~/Downloads/shscripts$ bash fun3.sh 2131 4543 5646 45645
兄臺,你傳入的腳本參數(shù),依次是 2131 4543 5646,并且參數(shù)個數(shù)一共是3
xiao123@xiao123:~/Downloads/shscripts$ bash fun3.sh 2131 4543 5646
兄臺,你傳入的腳本參數(shù),依次是 2131 4543 5646,并且參數(shù)個數(shù)一共是3
xiao123@xiao123:~/Downloads/shscripts$

函數(shù)實戰(zhàn)開發(fā)

  1. 檢測url是否正常,要求是函數(shù)開發(fā)形式
xiao123@xiao123:~/Downloads/shscripts$ cat check_url.sh
#!/bin/bashusage() {echo "Usage: $0 url"exit 1
}check_url() {wget --spider -q -o /dev/null --tries=1 -T 5 $1if [ $? -eq 0 ]thenecho "$1 is running..."elseecho "$1 is down..."fi
}main() {if [ $# -ne 1 ]thenusageficheck_url $1
}main $*
xiao123@xiao123:~/Downloads/shscripts$

運行結(jié)果

xiao123@xiao123:~/Downloads/shscripts$ bash check_url.sh www.baidu.com
www.baidu.com is running...
xiao123@xiao123:~/Downloads/shscripts$ bash check_url.sh www.baidu.coms
www.baidu.coms is down...
xiao123@xiao123:~/Downloads/shscripts$ bash check_url.sh www.baidu.coms  fd
Usage: check_url.sh url
xiao123@xiao123:~/Downloads/shscripts$ bash check_url.sh
Usage: check_url.sh url
xiao123@xiao123:~/Downloads/shscripts$

美化腳本

xiao123@xiao123:~/Downloads/shscripts$ cat check_url.sh
#!/bin/bash. /lib/lsb/init-functionsusage() {echo "Usage: $0 url"exit 1
}check_url() {wget --spider -q -o /dev/null --tries=1 -T 5 $1if [ $? -eq 0 ]thenlog_success_msg echo "$1 is running..."elselog_failure_msg "$1 is down..."fi
}main() {if [ $# -ne 1 ]thenusageficheck_url $1
}main $*
xiao123@xiao123:~/Downloads/shscripts$

運行結(jié)果:
slab

http://www.risenshineclean.com/news/7217.html

相關(guān)文章:

  • 重慶做的好的房產(chǎn)網(wǎng)站交換鏈接
  • 個人主頁怎么設(shè)置企業(yè)網(wǎng)站seo優(yōu)化公司
  • 找網(wǎng)站建設(shè)客戶怎樣進行關(guān)鍵詞推廣
  • 仿新聞網(wǎng)站百度賬號客服人工電話
  • 日本做仿牌網(wǎng)站在百度怎么創(chuàng)建自己的網(wǎng)站
  • 中國鐵路監(jiān)理建設(shè)協(xié)會網(wǎng)站搭建一個網(wǎng)站需要什么
  • 網(wǎng)頁設(shè)計流程圖繪制seo網(wǎng)站診斷方案
  • 佛山網(wǎng)站優(yōu)化有哪些熱門關(guān)鍵詞查詢
  • 網(wǎng)站建設(shè)工作室的營銷方式創(chuàng)業(yè)計劃書長沙靠譜的關(guān)鍵詞優(yōu)化
  • 網(wǎng)站建設(shè)優(yōu)化排名百度推廣登錄后臺
  • 幫傳銷組織做網(wǎng)站營業(yè)推廣怎么寫
  • 青島做網(wǎng)站多少錢東莞網(wǎng)站制作模板
  • 視頻鏈接生成競價推廣和seo的區(qū)別
  • 如何作做網(wǎng)站百度一下進入首頁
  • 公司網(wǎng)站 開源如何進行網(wǎng)絡(luò)營銷推廣
  • 做速賣通的素材有哪些網(wǎng)站做百度推廣的公司電話號碼
  • 代做網(wǎng)站作業(yè)廣告推廣平臺網(wǎng)站
  • 備案的域名可以做盜版電影網(wǎng)站嗎廣州各區(qū)正在進一步優(yōu)化以下措施
  • 建設(shè)銀行網(wǎng)站維修圖片做營銷策劃的公司
  • 甘孜州住房和城鄉(xiāng)規(guī)劃建設(shè)局網(wǎng)站外包公司為什么沒人去
  • 廣州企業(yè)網(wǎng)站建設(shè)公司bt磁力搜索神器
  • 做我的狗哪個網(wǎng)站可以看seo優(yōu)化技術(shù)是什么
  • 最新軟件發(fā)布平臺seo搜索引擎優(yōu)化課程總結(jié)
  • 西安正規(guī)網(wǎng)站建設(shè)報價重慶seo服務(wù)
  • 網(wǎng)站制作鄭州網(wǎng)站制作網(wǎng)站制作的重要性及步驟詳解
  • 企業(yè)如何建公司網(wǎng)站網(wǎng)站登錄入口
  • 可信網(wǎng)站辦理大數(shù)據(jù)精準營銷
  • 重慶免費網(wǎng)站制作寧波免費seo排名優(yōu)化
  • 網(wǎng)站添加谷歌地圖商城小程序開發(fā)哪家好
  • 網(wǎng)頁傳奇手游排行榜前十名吉林關(guān)鍵詞優(yōu)化的方法