我需要转换脚本:
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
我完全没有使用bash的经验,我的powershell知识是基础知识。退出代码是我这里遇到的主要问题。有什么想法吗?
答案 0 :(得分:0)
Test-Connection
on Microsoft Docs 上述SO问题应有助于解决您的问题。它们将帮助您了解bash脚本的功能以及采用方法。 exit_code
定义了两种语言的脚本返回。如果要使用相同的逻辑将脚本完全转换为PowerShell,将很难真正替换脚本的实际功能。如果您更改逻辑,则可能用单行替换。