简体   繁体   中英

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. Exit code is the main problem for me here. Any ideas please?

The above SO questions should be helpful in solving your problem. They will help you understand what the bash script does as well as adopting it. The exit_code defines the return of your script in both languages. 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. You could likely replace it with a single line if you change the logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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