Home > Operation and Maintenance > Linux Operation and Maintenance > Some summaries of Sh scripts in Linux

Some summaries of Sh scripts in Linux

黄舟
Release: 2017-06-05 10:34:59
Original
1750 people have browsed it

From the .netCore open source project, eShopOnContainers, its deployment is cross-platform and can be deployed on linux,docker, and it can also be run on linux. Write some integrated small scripts. This is a SH script that WeChat engineers provide us with a deployment and release plan.

#!/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.
Copy after login

The above solution mainly reflects some commands used during release, such as array, Traversal, conditional statements, delete files, release statements, etc., I wrote and practiced by myself

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
Copy after login

Everyone should pay attention when writing SH files, the carriage return characters of Linux and Windows are different. We can download the tool notepad++ for transcoding.

The above is the detailed content of Some summaries of Sh scripts in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template