LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-19-2008, 12:52 PM   #1
mmn357157
LQ Newbie
 
Registered: May 2007
Location: Bangalore
Distribution: RHEL
Posts: 20

Rep: Reputation: 0
Tidy shell script source file


Hi all,

Is there a tool to tidy up shell script source file and reformat it. Preferably I am looking for a perfect tool to do this.

Also I have heard it is possible to do with emacs editor but unfortunately it is looking very different and new from vi. Emacs is new to me and I could not find such an option myself yet.

Thanks,
mmn
 
Old 12-20-2008, 06:37 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Maybe "Bash Script Beautifier"?
http://www.arachnoid.com/linux/beautify_bash/
 
Old 12-20-2008, 06:45 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
"Beautify Bash" seems like the ultimate oxymoron......

To me, readable code simply means tabs and comments.....and maybe following a consistent style.....eg:

Code:
#Loop based on output of "ls" in current directory
for name in `ls`; do
    command
    command
done
is more readable than:

Code:
for name in `ls`; do; command; command; done #Loop based on output of "ls" in current directory
If you follow a consistent style, then what will the "beautification" utility add?
 
Old 12-20-2008, 12:53 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by pixellany View Post
"Beautify Bash" seems like the ultimate oxymoron......

To me, readable code simply means tabs and comments.....and maybe following a consistent style.....eg:

Code:
#Loop based on output of "ls" in current directory
for name in `ls`; do
    command
    command
done
is more readable than:

Code:
for name in `ls`; do; command; command; done #Loop based on output of "ls" in current directory
If you follow a consistent style, then what will the "beautification" utility add?
IMHO $(ls) is easier to read than `ls`



-C
 
Old 12-20-2008, 02:33 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by custangro View Post
IMHO $(ls) is easier to read than `ls`



-C
Perhaps, but it's one more keystroke....
 
Old 12-20-2008, 03:33 PM   #6
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
I have seen instances where a programmer made a minor modification to a piece of code, but he didn't like the way that comments were structured within the code.

Therefore he moved all the comments, so that they lined up.

When performing a diff comparison with the previous version of the code it was nearly impossible to see the actual change that had been made, as a fair proportion of the lines had changed!
 
Old 12-20-2008, 06:01 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by pixellany View Post
Perhaps, but it's one more keystroke....
It's not only easier to read: try nesting both and see which version "just works". Also note the backticks way doesn't remove trailing newlines.
 
Old 12-20-2008, 06:09 PM   #8
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Mods,
Is this thread heading "off topic"?
 
Old 12-20-2008, 07:33 PM   #9
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by pixellany
Perhaps, but it's one more keystroke....
I always stand alone when it comes to backticks...but since they are depricated (from what I've read)...I'll stick to $()

But for what it's worth, backticks are good when coding for backwards compatibility...you will have better luck having your code be "portable" if you use backticks (I'll give you guys _that_ much )

Also for those who care

http://wooledge.org:8000/BashFAQ/082

Besides...my boss won't let me use backticks

-C

Last edited by custangro; 12-20-2008 at 07:38 PM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to execute Source command in a shell script UltraSoul Linux - General 3 09-23-2010 10:13 AM
Need a shell script to turn a lined file into a comma seperated file Thaidog Linux - General 8 03-08-2008 07:19 PM
GPL License - Source code for shell script? kushalkoolwal Linux - General 33 02-19-2008 07:56 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
DISCUSSION: Tidy Up With HTML Tidy jeremy LinuxAnswers Discussion 0 10-10-2005 07:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:10 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