bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#A convenient way to check if bash scripts contain syntax errors using the bash -n command. | |
INTERVAL=10 | |
while [ 1 -gt 0 ]; do | |
bash -n "$1" | |
if [ $? == 0 ]; then | |
echo 'No Syntax errors were found. Keep marching on soldier!' | |
fi | |
sleep $INTERVAL; #check interval | |
clear | |
done |
vim script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
autocmd CursorHold,CursorHoldI * update |
How to get it working,
- Install vim if you don’t have it in your box.
- Copy the vimrc file to $HOME/.vim/
- Move CavemansBashEditor.sh to a location of your liking and run it providing the bash script that needs to be syntax checked as a script parameter e.g. ./CavemansBashEditor.sh /home/dumiduh/myscript.sh
- Leave the script running and refer to it while editing your script(Refer screenshot below).
Notes,
- The script uses ‘bash -n’ linux command and will only pick up syntax errors it picks up.
- The vimrc file changes the vim editors behavior so that it automatically saves changes, this behavior can be a pain at times so remove the file from $HOME/.vim/ when the script is not used.
- The script was tested on Ubuntu 14.04 with vim 2:7.4.052-1ubuntu3
No comments:
Post a Comment