Re: [SLE] comments in shell scripting

Sam Carleton <scarleton@activex-dev.com> writes:
/* block of code that is commented out */
Is there any way of doing that in a shell script? I know that I can put a pound sign (#) at the beginning of each line, but I don't know how to automate xemacs to do that and don't want to do that to 50 lines of code.
I use Emacs instead of XEmacs, so maybe commands might differ, or might not apply. The simplest is to put the mark on the first line and the point on the last line on the region (or vice-versa :-), or just drag over all the lines to comment, if you use transient mark mode. Point and mark should both in the same column (usually the leftmost for commenting, but it does not have to be), and then do: `C-x t # RET'. This should insert the pound sign on all lines. More precisely, replace zero character on each line -- as point and mark are in the same column -- by the given string. Removal works the same say. Put the mark on the first commented line, left of the first pound sign, and the point on the last line right of the last pound sign (or any other equivalent thing), then do: `C-x t RET'. This should remove the content of the selected rectangle, and add nothing on each line, instead. This `C-x t' command is very often useful to me. I would be surprised if there is nothing in shell-script mode for handling comments, but I never had to learn it, as the above is useful enough already. Another approach is to get on the first line of the region, and do command: `M-x query-replace-regexp RET ^ RET # RET', replying `SPC' on each line you want commented. Easier is to just select the region to comment (putting mark and point around it as usual), narrow to it with `C-x n n', execute the above `M-x ...', and reply a single `!' to do it all in one blow. You finally remove the narrowing restriction with `C-x n w'. XEmacs might vary slightly. Use `M-x query-replace-regexp RET ^# RET RET' for the converse operation. Short of doing those things, and to reply to your question more precisely, you might just bracket the whole region you want to skip like this: if false; then ... CODE TO SKIP... fi You have to be careful that the CODE TO SKIP uses properly nested constructs, if you do not want to introduce shell syntax errors. -- François Pinard http://www.iro.umontreal.ca/~pinard -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
participants (1)
-
pinard@iro.umontreal.ca