2

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?

6
  • A line with just $exit_code will output the exit code. Commented Feb 25, 2019 at 21:23
  • Please edit the question and explain what the bash script is supposed to do. Are you running the script on Windows or some *nix? Powershell and Windows work pretty different a way from *nix, so re-implementation can be quite different. Commented Feb 25, 2019 at 21:25
  • 3
    $exit_code = 0 assigns a value to the variable $exit_code in PowerShell. exit $exit_code is identical in PowerShell and bash. Now please go find a bash and a PowerShell tutorial. SO is neither a free translation service, nor a replacement for familiarizing yourself with the language(s) you're using. Commented Feb 25, 2019 at 21:54
  • 1
    Im assuming that you're hoping to go from running this script on linux to running this script on windows, that is probably going to mean that the various tools this script is expecting (ss, grep) will not be installed. Could you perhaps tell us what you want the script to do? it would be easier to just write the functionality directly rather than try and translate it. Commented Feb 25, 2019 at 22:33
  • Bash to Powershell script convert Commented Feb 26, 2019 at 0:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.