LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-28-2011, 11:36 AM   #1
lynne007
LQ Newbie
 
Registered: Jul 2010
Location: usa
Posts: 10

Rep: Reputation: 0
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.
 
Old 03-01-2011, 06:44 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
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
set autoindent showmode showmatch
Those options will be turned on every time you start the editor (showmdoe displays what editing mode you're in at the bottom of the screen).

EMACS user? On your own...

Hope this helps some.
 
Old 03-10-2011, 12:36 PM   #3
lynne007
LQ Newbie
 
Registered: Jul 2010
Location: usa
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 03-10-2011, 04:51 PM   #4
j1alu
Member
 
Registered: Apr 2009
Distribution: debian gnu/linux
Posts: 798

Rep: Reputation: Disabled
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
 
1 members found this post helpful.
Old 03-11-2011, 12:16 PM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Wow -- learn something good just about every day. Who knew? ESC-VG= and viola!

Gotta start reading those man pages...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stranger format to my scripts output shmo982 Programming 3 05-01-2009 02:58 PM
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
Shell script to compare blocks of strings? bruno buys Programming 10 04-15-2006 02:16 PM
How can I format my ext3 partition to use 1024 byte blocks and 1 inode per block? abefroman Linux - Hardware 1 11-26-2005 11:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration