Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Bash validator to catch unclosed brackets

  • 18-04-2016 08:04PM
    #1
    Registered Users, Registered Users 2 Posts: 262 ✭✭


    Hi, Im not sure how.. but..

    Bash's syntax validator

    sh -n <filename>


    gives the following line the all clear


    oot@serverX ~]# /opt/sun/script.sh list server-05


    Is there anything that checks for the brackets thay they are opened/closed as apt?


Comments

  • Registered Users, Registered Users 2 Posts: 2,660 ✭✭✭Baz_


    What is it that you're validating?

    It is unusual to have the "[\u@\h \W]# " (or any part of it) information embedded as part of a bash script file. I have tested it on my machine here and the "validator" doesn't balk when I save a script with that information in it and then "sh -n " the script, but when I try to run the script the shell then throws an error when it tries to execute that line.

    I presume you're seeing the same behaviour?

    When I tried "sh -n" against a script with an if statement (including some square brackets) it would only give a warning in rare circumstances, I played around with a number of different bracket variations to try to get it to fail. I don't think sh -n should be relied upon whatsoever for validating scripts.

    Try this: http://www.shellcheck.net/

    Just did a quick test, seems much more accurate.


Advertisement