bash: set - Perform a syntax check of a shell script.



  • Take into account the main readme for this section. README first.

    Description of set -n: Read commands but do not execute them.

    Perform syntax check, Intentionally deleted single parenthesis for the functions.

    set -n
    
    sys_clean_tmp ) {
    printf "\n\033[36m%s\\033[0m\n" "Cleaning temporary files"
    cd ~/tmp
    rm -f *.core
    }
    
    sys_clean_old ) {
    printf "\n\033[36m%s\\033[0m\n" "Cleaning temporary files"
    cd ~/tmp
    rm -f *.old
    }
    
    sys_clean_tmp
    sys_clean_old
    

    Running the script will produce syntax errors that can be fixed one a time. This is a good way to validate the syntax of your script without running the commands.

    $ ./clean
    ./clean: line 3: syntax error near unexpected token `)'
    ./clean: line 3: `sys_clean_tmp ) {'
    

    Comment out the set -n line after syntax of script has been checked.


Log in to reply
 

© Lightnetics 2024