Python Forum
script to check bash scripts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
script to check bash scripts
#1
unlike python, bash does not tell you where you left out a quote or { or }. it just tells you at the end that it hit EOF looking for a matching character. this script (for 3.6 or later) is a quickie i wrote to find just such a problem in a huge bash script i have (i have about 10 of these huge ones that i wish i had time to rewrite into python). yes, i do tend to code like this (one letter variables, etc) for quickies. do not use this as an example of good coding.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
n = 0
z = "'"+'"{'
for l in sys.stdin:
    n += 1
    l = l.strip()
    if l and l[0]=='#':
        continue
    for q in z:
        if q=='{':
            if l and l[-1]=='}':
                continue
            for x in range(len(l)):
                s=' '*x
                l = l.replace('()'+s+'{','()'+s)
            l = l.replace('}','{')
        s = l.split(q)
        if len(s)%2 == 0:
            print(f'oddetall av {q} i linje {n} ... {l}')
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
script to check bash scripts - by Skaperen - Sep-18-2019, 12:16 AM
RE: script to check bash scripts - by DeaD_EyE - Sep-18-2019, 06:31 AM
RE: script to check bash scripts - by buran - Sep-18-2019, 07:49 AM
RE: script to check bash scripts - by Skaperen - Sep-19-2019, 10:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A bash script that is a hack to enable very easy Python Imports vedant13 2 3,159 Aug-04-2018, 06:10 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020