wugong 發(fā)布系統(tǒng)是什么
乞丐版的wukong,可以實(shí)現(xiàn)線上集成,編譯打包褒傅,預(yù)發(fā)布驗(yàn)證等功能
簡(jiǎn)單介紹如何使用
1. 拿到需求后切分支開(kāi)發(fā)
訪問(wèn)后臺(tái)管理系統(tǒng)的首頁(yè),就是下面這個(gè)樣子
http://118.24.193.194/wugong/home/dist/index.html
前端同學(xué)需要開(kāi)發(fā)某一個(gè)需求袄友,第一步殿托,就是點(diǎn)擊創(chuàng)建分支按鈕,wugong會(huì)自動(dòng)化的創(chuàng)建一個(gè)分支剧蚣,開(kāi)發(fā)人員拿到分支后支竹,把wugong_project_1
的前端項(xiàng)目切換到分支上,開(kāi)發(fā)券敌,提交代碼到這個(gè)分支唾戚。
2. 提交代碼,預(yù)發(fā)布驗(yàn)證
然后代碼提交后待诅,點(diǎn)擊上預(yù)發(fā)布按鈕叹坦,wugong 會(huì)把你的代碼部署到預(yù)發(fā)布環(huán)境。
部署成功后卑雁,會(huì)讓開(kāi)發(fā)者設(shè)置cookie 為 YUFA=1
訪問(wèn)預(yù)發(fā)環(huán)境
通過(guò)設(shè)置cookie 為YUFA=1 然后訪問(wèn)http://118.24.193.194(不要帶任何路徑)
3. 發(fā)布到正式服務(wù)
驗(yàn)證預(yù)發(fā)沒(méi)問(wèn)題后募书,點(diǎn)擊【上正式環(huán)境】按鈕绪囱,wugong系統(tǒng)會(huì)把代碼部署到正式環(huán)境,去掉cookie訪問(wèn)http://118.24.193.194 進(jìn)行正式驗(yàn)證莹捡。
wugong 發(fā)布系統(tǒng)架構(gòu)
服務(wù)器上的情況鬼吵,和mac上的一模一樣
兩個(gè)目錄比較關(guān)注
nginx 配置
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n370" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> /etc/nginx/nginx.conf</pre>
后端服務(wù)架構(gòu)
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n420" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> /var/www/</pre>
這個(gè)目錄下面有什么呢?
直接看服務(wù)器的目錄
【看圖吧】
nginx 配置兩個(gè)作用:
代理服務(wù)器:代理靜態(tài)資源篮赢,代理node服務(wù)
通過(guò) cookie 控制 預(yù)發(fā)布 / 正式發(fā)布
難點(diǎn)
個(gè)人覺(jué)得主要難點(diǎn)有兩個(gè)齿椅,nginx配置,用 命令行 / 腳本 去構(gòu)建启泣,打包涣脚,部署到各種環(huán)境
nginx配置的很爛,就不給大家介紹了 (以后好好研究一下)
接下來(lái)介紹命令行 / 腳本的知識(shí)點(diǎn)寥茫,作為一個(gè)前端的同學(xué)遣蚀,命令行或者腳本可能更能提高工作效率吧
command / shell / terminal / bash
command (命令) 只是普通的一句話,比如說(shuō)echo hello
, i am strong
纱耻,如果對(duì)于不懂英語(yǔ)的人芭梯,這就是普通的文本,沒(méi)有任何意義
shell相當(dāng)于翻譯弄喘,負(fù)責(zé)解釋出真實(shí)的意義玖喘,把echo hello
解釋計(jì)算機(jī)能聽(tīng)懂的意思
terminel ,就是黑漆漆的命令行窗口限次,是通向shell的窗口芒涡。
shell 有不同的類(lèi)型,同樣的一行命令卖漫,不同的shell 可以解釋出不同的意思。
最常見(jiàn)的shell 被稱(chēng)為 bash shell
command 本質(zhì)是赠群?
command 本質(zhì)就是裝在你電腦上的小程序羊始。
date
, ls
,cd
都是程序, 不相信可以使用which
命令會(huì)找到查描,這個(gè)被執(zhí)行的程序究竟在哪里
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n11" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> which npm</pre>
如果找到突委,則返回該程序的目錄:
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n13" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> /Users/dudu/.nvm/versions/node/v10.11.0/bin/npm</pre>
如果沒(méi)有找到,則返回 command not found
那么究竟是怎么找到呢冬三?
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n16" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> echo $PATH
?
/Users/dudu/.nvm/versions/node/v10.11.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</pre>
這里的目錄被 :
分割匀油,如果第一個(gè)目錄沒(méi)有找到,則移動(dòng)到下一個(gè)勾笆。會(huì)先執(zhí)行第一個(gè)找到的程序敌蚜。
因此,如果我們想生成自己的命令窝爪,那么只需要在上面的路徑中弛车,新增自己的路徑就好了
自己生成一個(gè)腳本
-
創(chuàng)建一個(gè)bin目錄 bin 目錄是約定俗稱(chēng)的用來(lái)放可執(zhí)行文件的
bin目錄放在任何目錄都o(jì)k
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n46" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> mkdir ~/bin</pre>
-
創(chuàng)建一個(gè)腳本文件
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n77" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> cd /var/www/bin
touch hello-world.sh</pre>腳本文件就像普通的文本文件齐媒,以
.sh
結(jié)尾。腳本文件之所以可以被執(zhí)行纷跛,就是有一個(gè)解釋器喻括,會(huì)從
.sh
文件中讀取每一行作為要執(zhí)行的命令這個(gè)
hello-world.sh
可以用文本編輯器編輯,增加第一行贫奠,以固定的#!
開(kāi)頭唬血,后面指向解釋器的地址。<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n85" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> #!/bin/bash
?
echo Hello, World!</pre> -
此時(shí)該``hello-world.sh
還是一個(gè)普通的文本唤崭,需要變成可執(zhí)行文件 執(zhí)行命令
hello-world.sh`刁品,你會(huì)發(fā)現(xiàn)<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n109" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> -bash: hello-world: command not found</pre>
我們還需要做兩件事,第一個(gè)就是把這個(gè)普通的文本文件變成可執(zhí)行文件
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n112" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> chmod u+x hello-world.sh</pre>
-
在
~/.bash_profile
文件中浩姥,新增該文件的路徑挑随。<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n138" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> export PATH=$PATH:/var/www/bin</pre>
上面代碼的意思是,在$PATH變量后面勒叠,新增
/var/www/bin
注意哦兜挨,如果是使用
zsh
的話,需要在~/.zshrc
的目錄中增加<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n145" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> source ~/.bash_profile;</pre>
最后眯分,在任何地方執(zhí)行hello-word.sh
都可以執(zhí)行了
腳本中的變量
變量在定義時(shí)候不用$
, 在使用的時(shí)候要用$
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n157" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> #!/bin/bash
?
who="World"
?
echo Hello, $who!</pre>
注意哦拌汇, who = "World"
是無(wú)效的,因?yàn)橘x值號(hào)兩邊不能有空格
從命令中讀取參數(shù)
命令中帶參數(shù)大家都很熟悉了弊决,比如說(shuō) cd ./test
的./test
噪舀。
從命令上拿到參數(shù),$1
是拿到第一個(gè)參數(shù)飘诗,$2
是拿到第二個(gè)參數(shù)
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n225" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> #!/bin/bash
?
echo 2</pre>
$0 - bash script的名字
$# - 參數(shù)的個(gè)數(shù)
$@ - 所有的參數(shù)
$? - The exit status of the most recently run process.
$$ - 當(dāng)前腳本的pid
$USER - 當(dāng)前是誰(shuí)在跑這個(gè)腳本
$HOSTNAME - 當(dāng)前是哪個(gè)機(jī)器在跑這個(gè)腳本
$SECONDS - 這個(gè)腳本跑了多久了
$RANDOM - 返回一個(gè)隨機(jī)數(shù)
$LINENO - 返回當(dāng)前的行數(shù)
單引號(hào)雙引號(hào)
字符串變量最好加單引號(hào)与倡,或者雙引號(hào),因?yàn)榭崭駮?huì)被腳本認(rèn)為是分割命令昆稿。 下面是錯(cuò)誤的:
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n282" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> myvar=Hello World
-bash: World: command not found</pre>
單引號(hào)會(huì)把里面的$balabala
當(dāng)成普通的字符串纺座,雙引號(hào)會(huì)把$balabala
當(dāng)成變量,
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n293" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> myvar='Hello World'
echo myvar"
echo myvar'
echo myvar</pre>
判斷條件
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n170" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; background-position: inherit inherit; background-repeat: inherit inherit;"> #!/bin/bash
?
echo How old are you?
?
read age
?
if [ "$age" -gt 20 ]
then
echo You can drink.
else
echo You are too young to drink.
fi</pre>
語(yǔ)法跟著模板寫(xiě)就好了溉潭,唯一需要注意的是:
Bash Operator | Operator | Description |
---|---|---|
-eq |
== |
Equal |
-ne |
!= |
Not equal |
-gt |
> |
Greater than |
-ge |
>= |
Greater than or equal |
-lt |
< |
Less than |
-le |
<= |
Less than or equal |
-z |
== null |
Is null |
在node中執(zhí)行腳本
-
直接在node中執(zhí)行
語(yǔ)法很簡(jiǎn)單, 如下使用
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="javascript" contenteditable="false" cid="n27" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> // 用子進(jìn)程來(lái)執(zhí)行shell腳本
const exec = require('child_process').execSync;
exec('echo hello~')</pre>也可以多條執(zhí)行净响,也可以指定腳本執(zhí)行的目錄
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="javascript" contenteditable="false" cid="n29" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> // 用子進(jìn)程來(lái)執(zhí)行shell腳本
const exec = require('child_process').execSync;
?
exec('git checkout master', {cwd: '/var/www/home/wugong_project_1'})
exec('git pull origin master', {cwd: '/var/www/home/wugong_project_1'})
exec(git checkout -b ${project}_${branch}
, {cwd: '/var/www/home/wugong_project_1'})
exec(git push origin ${project}_${branch}
, {cwd: '/var/www/home/wugong_project_1'})</pre> -
使用bash script腳本執(zhí)行
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="javascript" contenteditable="false" cid="n405" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"> // 用子進(jìn)程來(lái)執(zhí)行shell腳本
const exec = require('child_process').execSync;
?
exec(/var/www/wugong/serve/shell/create_branch.sh ${project} ${branchName}
)</pre>