Linux~Sh指令碼一點自己的總結,linuxsh指令碼

來源:互聯網
上載者:User

Linux~Sh指令碼一點自己的總結,linuxsh指令碼

從.netCore開源項目來看,eShopOnContainers來說,它的部署是跨平台的,可以部署在linux,docker上,在linux上運行它也可以寫一些整合的小指令碼,這是工程師為我們提供一個部署發布方案的SH指令碼

#!/bin/bashdeclare -a projectList=(    '../src/Services/Catalog/Catalog.API'    '../src/Services/Basket/Basket.API'    '../src/Services/Ordering/Ordering.API'    '../src/Services/Identity/Identity.API'    '../src/Web/WebMVC'    '../src/Web/WebSPA'    '../src/Web/WebStatus')# Build SPA app# pushd $(pwd)../src/Web/WebSPA# npm run build:prodfor project in "${projectList[@]}"do    echo -e "\e[33mWorking on $(pwd)/$project"    echo -e "\e[33m\tRemoving old publish output"    pushd $(pwd)/$project    rm -rf obj/Docker/publish    echo -e "\e[33m\tRestoring project"    dotnet restore    echo -e "\e[33m\tBuilding and publishing projects"    dotnet publish -o obj/Docker/publish    popddone# remove old docker images:images=$(docker images --filter=reference="eshop/*" -q)if [ -n "$images" ]; then    docker rm $(docker ps -a -q) -f    echo "Deleting eShop images in local Docker repo"    echo $images    docker rmi $(docker images --filter=reference="eshop/*" -q) -ffi# No need to build the images, docker build or docker compose will# do that using the images and containers defined in the docker-compose.yml file.

上面的解決主要體現了發布時用的一些命令,如數組,遍曆,條件陳述式,刪除檔案,發布語句等,我自己寫練了練手

declare -a arr=(12345)for i in "${arr[@]}"do if [ $i == 2 ]then   echo "a is equal to 2"else   echo "a is not equal to 2"fidonedeclare -a projectList=(    '../src/Services/Catalog/Catalog.API'    '../src/Services/Basket/Basket.API'    '../src/Services/Ordering/Ordering.API'    '../src/Services/Identity/Identity.API'    '../src/Web/WebMVC'    '../src/Web/WebSPA'    '../src/Web/WebStatus')for project in "${projectList[@]}"do    echo -e "\e[33m工作在目錄 $(pwd)/$project"    echo -e "\e[33m\tRemoving old publish output"done

大家在寫SH檔案時要注意,linux與windows的斷行符號符不一樣,我們可以下載notepad++這個工具來進行轉碼。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.