2019-01-16

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

image

前端同學(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è)分支唾戚。

image

2. 提交代碼,預(yù)發(fā)布驗(yàn)證

然后代碼提交后待诅,點(diǎn)擊上預(yù)發(fā)布按鈕叹坦,wugong 會(huì)把你的代碼部署到預(yù)發(fā)布環(huán)境。

image

部署成功后卑雁,會(huì)讓開(kāi)發(fā)者設(shè)置cookie 為 YUFA=1 訪問(wèn)預(yù)發(fā)環(huán)境

image

通過(guò)設(shè)置cookie 為YUFA=1 然后訪問(wèn)http://118.24.193.194(不要帶任何路徑)

image

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è)作用:

  1. 代理服務(wù)器:代理靜態(tài)資源篮赢,代理node服務(wù)

  2. 通過(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, lscd 都是程序, 不相信可以使用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è)腳本

  1. 創(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>

  2. 創(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>

  3. 此時(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>

  4. ~/.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 1 echo2</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 // Hello World newvar="Moremyvar"
echo newvar //More Hello World newvar='Moremyvar'
echo newvar //Moremyvar</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í)行腳本

  1. 直接在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>

  2. 使用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>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市喳瓣,隨后出現(xiàn)的幾起案子馋贤,更是在濱河造成了極大的恐慌,老刑警劉巖畏陕,帶你破解...
    沈念sama閱讀 218,036評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件配乓,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)扰付,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)堤撵,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人羽莺,你說(shuō)我怎么就攤上這事实昨。” “怎么了盐固?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,411評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵荒给,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我刁卜,道長(zhǎng)志电,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,622評(píng)論 1 293
  • 正文 為了忘掉前任蛔趴,我火速辦了婚禮挑辆,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘孝情。我一直安慰自己鱼蝉,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,661評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布箫荡。 她就那樣靜靜地躺著魁亦,像睡著了一般。 火紅的嫁衣襯著肌膚如雪羔挡。 梳的紋絲不亂的頭發(fā)上洁奈,一...
    開(kāi)封第一講書(shū)人閱讀 51,521評(píng)論 1 304
  • 那天,我揣著相機(jī)與錄音绞灼,去河邊找鬼利术。 笑死,一個(gè)胖子當(dāng)著我的面吹牛镀赌,可吹牛的內(nèi)容都是我干的氯哮。 我是一名探鬼主播,決...
    沈念sama閱讀 40,288評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼商佛,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了姆打?” 一聲冷哼從身側(cè)響起良姆,我...
    開(kāi)封第一講書(shū)人閱讀 39,200評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎幔戏,沒(méi)想到半個(gè)月后玛追,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,644評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,837評(píng)論 3 336
  • 正文 我和宋清朗相戀三年痊剖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了韩玩。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,953評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡陆馁,死狀恐怖找颓,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情叮贩,我是刑警寧澤击狮,帶...
    沈念sama閱讀 35,673評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站益老,受9級(jí)特大地震影響彪蓬,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜捺萌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,281評(píng)論 3 329
  • 文/蒙蒙 一档冬、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧桃纯,春花似錦酷誓、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,889評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至驮配,卻和暖如春娘扩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背壮锻。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,011評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工琐旁, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人猜绣。 一個(gè)月前我還...
    沈念sama閱讀 48,119評(píng)論 3 370
  • 正文 我出身青樓灰殴,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親掰邢。 傳聞我的和親對(duì)象是個(gè)殘疾皇子牺陶,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,901評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,381評(píng)論 0 5
  • 一、Python簡(jiǎn)介和環(huán)境搭建以及pip的安裝 4課時(shí)實(shí)驗(yàn)課主要內(nèi)容 【Python簡(jiǎn)介】: Python 是一個(gè)...
    _小老虎_閱讀 5,746評(píng)論 0 10
  • 第 2 章 SHELL 基礎(chǔ)知識(shí)2.1 shell腳本我們?cè)谏厦婧?jiǎn)單介紹了一下什么是shell腳本辣之,現(xiàn)在我們來(lái)進(jìn)一...
    LiWei_9e4b閱讀 1,571評(píng)論 0 0
  • 1.創(chuàng)建文件夾 !/bin/sh mkdir -m 777 "%%1" 2.創(chuàng)建文件 !/bin/sh touch...
    BigJeffWang閱讀 10,059評(píng)論 3 53
  • 什么是運(yùn)維 術(shù)語(yǔ)名詞 IDC--(Internet Data Center)互聯(lián)網(wǎng)數(shù)據(jù)中心怀估,主要服務(wù)包括整機(jī)租用狮鸭、...
    lyh165閱讀 2,705評(píng)論 0 19