Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Convert shell script to python  (Read 57309 times)

0 Members and 2 Guests are viewing this topic.

Santosh

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 10
    Convert shell script to python
    « on: May 05, 2022, 03:31:38 AM »
    I have written a shell script and I need the same script in python to execute it for windows.

    Code: [Select]
    #!/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


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Convert shell script to python
    « Reply #1 on: May 06, 2022, 05:00:43 PM »
    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



      Rookie
    • Thanked: 1
      • Experience: Beginner
      • OS: Windows 10
      Re: Convert shell script to python
      « Reply #2 on: April 07, 2023, 12:28:18 AM »
      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/.