is there software to format shell scripts? especially if-then blocks?
I was wondering if there is any software to logically reformat shell scripts - for example, like HTMLTIDY does with HTML? or PERLTIDY does with Perl?
The reason I'm asking is I am going through a shell script with a 3 page IF-then block.. and what seems like a million smaller if-then blocks within this bigger block. yikes! And nothing is formatted, indented, commented to make it easier to figure out. Thanks. |
A quick Google search for "beautify shell program" turns up quite a few... take a look, see what you think.
If you're doing shell programming or editing of your own and you use vi or vim you can turn on autoindent. What that does is you hit the tab key and the editor will keep the indent at that tab for you each time you hit the carriage return; and additional tab will add additional indent, Control-D will undent one step at a time back to the left margin. Handy. If you're programming in C, you can set showmatch. That will cause the cursor to flip back and forth showing a match (or not if you miss one) for parenthesis (), brackets [] and braces {}. showmatch works in any file, so if you open a paren ( and you enter a ) you'll get the cursor flip showing the match (and if you do too many closes, you'll get told about it). Also handy. If you create a file in your home directory named .exrc with content like this (then log out and back in again so it take effect) Code:
cat .exrc EMACS user? On your own... Hope this helps some. |
thanks.. sorry for not replying sooner. I didn't realize I had a response.
I am using linux remote, via an eclipse application. I saw the ruby formatter when I googled, but I don't want to install ruby on the rails. I've used editors that check for matching braces, parentheses, etc., and they are very nice. However, in a bash shell, for the if-then-else-fi(endif) type of logic construct, there is no enclosing braces, parentheses. So, a bash shell formatter would have to use command analysis to reconstruct the source in a logical manner. thanks, anyway. |
not that i would have done it before,but vim is the general answer (similar to 42).
esc and then V G = is what you are looking for. You need to be at line 0, type V to turn on visual mode, the type G to match up to the last line. then hit the = and all your bash should be in correct format. http://www.cs.swarthmore.edu/help/vim/reformatting.html |
Wow -- learn something good just about every day. Who knew? ESC-VG= and viola!
Gotta start reading those man pages... |
All times are GMT -5. The time now is 05:43 PM. |