Add Comment
|
Related Links
|
TrackBack
Multi-Line Comments in Shell ScriptThe UNIX shell script is a powerful beast. You can pretty much write anything in shell scripts that you can also write in other languages. The thing is that UNIX shell script only support single line comments, with a hash (#) mark. So to comment out the following example, you'd have to put a hash mark in front of every line: # if [ -f "${distroFile}" ] Well, that's a lot of work. As you can see in the example above, that's seven hash marks. And you'd have to change the cursor position for every hash mark. Don't you wish there is a C or Java-like multi-line comment (/* */) sequence? Well, today, I got the bright idea of comment out multi-line shell script source codes by surrounding them in function calls. The same example above would be changed to the following: comment1 () Now, isn't that must easier and neater? Chieh Cheng This is another way: :<<supercalifragilisticexpialidocious Reference: http://www.unix.com/shell-programming-scripting/39478-block . . . Jatin Sharma Really useful considering the behavior of the vi editor in Unix/Linux. Good Stuff. Thank you Venkatagiri Vatlam csh doesn't have functions. But Jatin's supercalifragilisticexpialidocious example works great in csh. The function method works even if you put the multi-line comments inside another function. Chieh Cheng Thanks, i served too!! Hans Ancieta Nice style of commenting....looks neat and classy...;) xtatic #!/bin/bash but comment(){} its working ...really nice and neat trick. Suprabhat I was laughing when I saw this. Real Neat. Good Job ! Avinash well, apparently if I have developer's musing that I want to record this method wouldn't work, right? - cause stuff like a TODO list that I want to maintain as part of a future release wouldn't be allowed under a comment unless i qualify every statement that I write there by an echo command. Sam Or create a specific function for comments (this functions does nothing, by the way): comment() { :; } now you can enter comments anywhere with any amount of lines: echo "hello worlds" Donat Callens
Add Comment
|
Related Links
|
TrackBack
Did your message disappear? Read the Forums FAQ. Add CommentSpam Control | * indicates required field TrackBackTrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites. Send Ping | TrackBack URL | Spam Control No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here. Messages, files, and images copyright by respective owners. |
Products
|
Services
46 Users Online
|
Copyright © 1996 - 2024. All Rights Reserved. |