Home Operation and Maintenance Linux Operation and Maintenance The definition and use of PowerShell and Bash

The definition and use of PowerShell and Bash

Jun 21, 2017 am 11:13 AM
bash powershell introduce

PowerShell是运行在windows平台的脚本,而Bash是运行在linux平台的脚本

现在bash能做的事情,PowerShell也能做,PowerShell的强大之处是它可以管理windows服务器(特别是域domain),现在的开源PowerShell 也可以管理Linux和Mac(通过PSRP)。

下载最新的PS程序


安装后它会有powershell和它的开发IDE工具,ISE,非常不错!

一、进行powershell的程序

二、创建脚本,简单的Helloworld.ps1

任务的自动化是以程序文件或者可执行脚本文件为基础的,PowerShell也支持将命令列表做成脚本文件来执行。以下是Helloworld.ps1脚本文件的内容:

$a = "Hello World!"$a
echo $a > a.txt
dir a.txt
Copy after login

Helloworld.ps1脚本文件的执行情况结果如下:

PS E:\>.\Helloworld.ps1  --注意在执行它时要加.\,表示当前上当下的文章,类似于centos里的文件执行方法<br>
<code class="javascript plain">Hello world!
Directory: E:\
Mode                LastWriteTime     Length   Name                                                                     
----                -------------     ------ ----                                                                     

-a---         5/30/2017   4:56 PM         16 a.txt  <br>

下面是在eShopOnContainers上的一个例子,分别用ps和bash实现了程序的部署

#!/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[@]}"doecho -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

powershell代码如下

Param([string] $rootPath)
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path

Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellowif ([string]::IsNullOrEmpty($rootPath)) {
    $rootPath = "$scriptPath\.."}
Write-Host "Root path used is $rootPath" -ForegroundColor Yellow

$projectPaths = 
    @{Path="$rootPath\src\Web\WebMVC";Prj="WebMVC.csproj"},
    @{Path="$rootPath\src\Web\WebSPA";Prj="WebSPA.csproj"},
    @{Path="$rootPath\src\Services\Identity\Identity.API";Prj="Identity.API.csproj"},
    @{Path="$rootPath\src\Services\Catalog\Catalog.API";Prj="Catalog.API.csproj"},
    @{Path="$rootPath\src\Services\Ordering\Ordering.API";Prj="Ordering.API.csproj"},
    @{Path="$rootPath\src\Services\Basket\Basket.API";Prj="Basket.API.csproj"}
    @{Path="$rootPath\src\Web\WebStatus";Prj="WebStatus.csproj"}

$projectPaths | foreach {
    $projectPath = $_.Path
    $projectFile = $_.Prj
    $outPath = $_.Path + "\obj\Docker\publish"$projectPathAndFile = "$projectPath\$projectFile"Write-Host "Deleting old publish files in $outPath" -ForegroundColor Yellow
    remove-item -path $outPath -Force -Recurse -ErrorAction SilentlyContinue
    Write-Host "Publishing $projectPathAndFile to $outPath" -ForegroundColor Yellow
    dotnet restore $projectPathAndFile
    dotnet build $projectPathAndFile
    dotnet publish $projectPathAndFile -o $outPath
}


########################################################################################
# Delete old eShop Docker images
########################################################################################

$imagesToDelete = docker images --filter=reference="eshop/*" -q

If (-Not $imagesToDelete) {Write-Host "Not deleting eShop images as there are no eShop images in the current local Docker repo."} 
Else 
{
    # Delete all containers
    Write-Host "Deleting all containers in local Docker Host"docker rm $(docker ps -a -q) -f
    
    # Delete all eshop images
    Write-Host "Deleting eShop images in local Docker repo"Write-Host $imagesToDelete
    docker rmi $(docker images --filter=reference="eshop/*" -q) -f
}

# WE DON'T NEED DOCKER BUILD AS WE CAN RUN "DOCKER-COMPOSE BUILD" OR "DOCKER-COMPOSE UP" AND IT WILL BUILD ALL THE IMAGES IN THE .YML FOR US
Copy after login

自己感觉,这两个东西在以后的程序部署上都会发挥各自强大的力量!

The above is the detailed content of The definition and use of PowerShell and Bash. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed introduction to what wapi is Detailed introduction to what wapi is Jan 07, 2024 pm 09:14 PM

Users may have seen the term wapi when using the Internet, but for some people they definitely don’t know what wapi is. The following is a detailed introduction to help those who don’t know to understand. What is wapi: Answer: wapi is the infrastructure for wireless LAN authentication and confidentiality. This is like functions such as infrared and Bluetooth, which are generally covered near places such as office buildings. Basically they are owned by a small department, so the scope of this function is only a few kilometers. Related introduction to wapi: 1. Wapi is a transmission protocol in wireless LAN. 2. This technology can avoid the problems of narrow-band communication and enable better communication. 3. Only one code is needed to transmit the signal

Detailed explanation of whether win11 can run PUBG game Detailed explanation of whether win11 can run PUBG game Jan 06, 2024 pm 07:17 PM

Pubg, also known as PlayerUnknown's Battlegrounds, is a very classic shooting battle royale game that has attracted a lot of players since its popularity in 2016. After the recent launch of win11 system, many players want to play it on win11. Let's follow the editor to see if win11 can play pubg. Can win11 play pubg? Answer: Win11 can play pubg. 1. At the beginning of win11, because win11 needed to enable tpm, many players were banned from pubg. 2. However, based on player feedback, Blue Hole has solved this problem, and now you can play pubg normally in win11. 3. If you meet a pub

Introduction to Python functions: Introduction and examples of exec function Introduction to Python functions: Introduction and examples of exec function Nov 03, 2023 pm 02:09 PM

Introduction to Python functions: Introduction and examples of exec function Introduction: In Python, exec is a built-in function that is used to execute Python code stored in a string or file. The exec function provides a way to dynamically execute code, allowing the program to generate, modify, and execute code as needed during runtime. This article will introduce how to use the exec function and give some practical code examples. How to use the exec function: The basic syntax of the exec function is as follows: exec

Developing with MySQL and PowerShell: How to implement data encryption and decryption functions Developing with MySQL and PowerShell: How to implement data encryption and decryption functions Aug 01, 2023 pm 01:52 PM

Developing with MySQL and PowerShell: How to Implement Data Encryption and Decryption Functions Overview: In modern Internet applications, protecting the security of sensitive data is crucial. To ensure user privacy and data integrity, developers often use data encryption technology. This article will introduce how to use MySQL database and PowerShell script to implement data encryption and decryption functions. 1. Data encryption in MySQL database MySQL provides a variety of encryption functions and algorithms to ensure that data stored in

Detailed introduction to whether i5 processor can install win11 Detailed introduction to whether i5 processor can install win11 Dec 27, 2023 pm 05:03 PM

i5 is a series of processors owned by Intel. It has various versions of the 11th generation i5, and each generation has different performance. Therefore, whether the i5 processor can install win11 depends on which generation of the processor it is. Let’s follow the editor to learn about it separately. Can i5 processor be installed with win11: Answer: i5 processor can be installed with win11. 1. The eighth-generation and subsequent i51, eighth-generation and subsequent i5 processors can meet Microsoft’s minimum configuration requirements. 2. Therefore, we only need to enter the Microsoft website and download a "Win11 Installation Assistant" 3. After the download is completed, run the installation assistant and follow the prompts to install Win11. 2. i51 before the eighth generation and after the eighth generation

The difference between powershell and cmd The difference between powershell and cmd Jul 25, 2023 am 11:29 AM

The difference between powershell and cmd is: 1. Different syntax and commands. CMD uses command syntax based on MS-DOS, while Powershell uses more powerful syntax based on the .NET framework; 2. Different script support, Powershell has powerful script support, and CMD supports simple scripts; 3. Different object orientation. Powershell is based on the object-oriented programming model, while CMD is not object-oriented; 4. Different scalability; 5. Different output formats; 6. Different cross-platform support systems.

Introducing the latest Win 11 sound tuning method Introducing the latest Win 11 sound tuning method Jan 08, 2024 pm 06:41 PM

After updating to the latest win11, many users find that the sound of their system has changed slightly, but they don’t know how to adjust it. So today, this site brings you an introduction to the latest win11 sound adjustment method for your computer. It is not difficult to operate. And the choices are diverse, come and download and try them out. How to adjust the sound of the latest computer system Windows 11 1. First, right-click the sound icon in the lower right corner of the desktop and select "Playback Settings". 2. Then enter settings and click "Speaker" in the playback bar. 3. Then click "Properties" on the lower right. 4. Click the "Enhance" option bar in the properties. 5. At this time, if the √ in front of "Disable all sound effects" is checked, cancel it. 6. After that, you can select the sound effects below to set and click

How to run PowerShell as an administrator in Win10. How to run PowerShell as an administrator in Win10. Jul 18, 2023 pm 02:05 PM

WindowsPowerShell is a Windows command line shell designed for system administrators. Windows PowerShell includes interactive prompts and scripting environments that can be used individually or in combination. However, many PowerShell commands require elevated or administrator rights, and you need to launch a PowerShell prompt to execute them. How to run PowerShell as an administrator in Win10. Method 1: Use the Windows 10 Start Menu context menu. When you right-click on the Windows 10 Start menu, a context menu appears, allowing you to quickly launch commonly used management programs. The context menu contains a window called Windo

See all articles