首頁 >運維 >linux運維 >Linux中Sh腳本的一些總結

Linux中Sh腳本的一些總結

黄舟
黄舟原創
2017-06-05 10:34:591756瀏覽

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

#!/bin/bash
declare -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
    popd
done
# 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) -f
fi
# 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"fi
done
declare -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++這個工具來進行轉碼。

以上是Linux中Sh腳本的一些總結的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn