简体   繁体   English

将bash转换为powershell脚本?

[英]Convert bash into powershell script?

I need to convert script: 我需要转换脚本:

s#!/bin/bash

if [ $# -ne 1 ]; then
        echo "Usage:"
        echo ${0##*/}" <port>"
        echo
        exit 1
fi

r=`ss -ln6tp | grep -c ":::$1"`
 if [ $r -ne 1 ]; then
        echo "Agent on port $1 is not listening."
        exit_code=2
 else
        echo "Agent listening on port $1"
        exit_code=0
 fi

exit $exit_code

I don't have experience with bash at all and my powershell knowledge is basic. 我完全没有使用bash的经验,而我的powershell知识是基础知识。 Exit code is the main problem for me here. 退出代码是我这里遇到的主要问题。 Any ideas please? 有什么想法吗?

The above SO questions should be helpful in solving your problem. 上述SO问题应该有助于解决您的问题。 They will help you understand what the bash script does as well as adopting it. 它们将帮助您了解bash脚本的功能以及采用方法。 The exit_code defines the return of your script in both languages. exit_code用两种语言定义脚本的返回。 You will have a hard time to actually replace the actual functionality of the script if you want to entirely convert it into PowerShell using the same logic. 如果要使用相同的逻辑将脚本完全转换为PowerShell,将很难真正替换脚本的实际功能。 You could likely replace it with a single line if you change the logic. 如果更改逻辑,则可能用单行替换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM