Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Bash validator to catch unclosed brackets

Options
  • 18-04-2016 8:04pm
    #1
    Registered Users 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 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