我需要转换脚本:
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知识是基本的。出口代码对我来说是主要问题。有什么想法吗?
- $#在bash中的用途是什么
- PowerShell中的"退出"到底是什么?
- 如何将论点传递给PowerShell脚本?
- Microsoft文档上的
Test-Connection
上述问题应该有助于解决您的问题。他们将帮助您了解BASH脚本的作用以及采用它。exit_code
用两种语言定义了脚本的返回。如果您想使用相同的逻辑将其完全转换为PowerShell,那么您将很难实际替换脚本的实际功能。如果更改逻辑,则可能会用一行替换。