Convert shell script to python

Started by Santosh, May 05, 2022, 03:31:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Santosh

I have written a shell script and I need the same script in python to execute it for windows.

#!/usr/bin/env bash

sonar_token=$1
sonar_server=$2
sonar_project_key=$3


echo "Fetching the Sonar Quality gate status using api"
quality_gatesstatus=$(curl -u $sonar_token: https://$sonar_server/api/qualitygates/project_status?pullRequest=$PullRequestId | grep -Po '"status": *\K"[^"]*"')

echo "the Sonar quality gates for current analysis is: $quality_gatesstatus"
if ("$quality_gatesstatus" != "OK") && ("$quality_gatesstatus" != "NONE")
then
   echo "Check Sonar server and fix the issues"
   echo $quality_gatesstatus
   exit 1
else
   echo "No code violations found"
   exit 0
fi


I am trying but i am failing to do that, please help us on that.

Geek-9pm

The problem is you are calling is a shell script.  You to tell use it is bash and what version  of bash.
Here is a possible answer:
https://stackoverflow.com/questions/2839810/converting-a-bash-script-to-python-small-script

Sorry I can not do it. I am getting too old.  :'(

satineeraj

Converting a shell script to Python involves translating the commands and logic from shell syntax to Python syntax.

Shell Script:

#!/bin/sh

echo "Enter your name:"
read name
echo "Hello, $name"

Python Script:

#!/usr/bin/env python

name = input("Enter your name: ")
print("Hello, " + name)

For more reference check this StackOverflow post: https://stackoverflow.com/questions/49982459/how-to-convert-shell-script-into-python-script
Life doesn't always give u a second chance U never get a second chance to create the first impression So make ur first chance counthttps://vidmate.click/https://vidmateapp.winhttps://myfiosgateway.win/.