Home >Operation and Maintenance >Linux Operation and Maintenance >Some summaries of Sh scripts in Linux
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.
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
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!