tags:

views:

179

answers:

4

I'd like to be able to comment out a single flag in a one-line command. Bash only seems to have `from # till end-of-line' comments. I'm looking at tricks like:

ls -l $([ ] && -F is turned off) -a /etc

It's ugly, but better than nothing. Anybody has any better suggestions?

UPDATE

The following seems to work, but I'm not sure whether it is portable:

ls -l `# -F is turned off` -a /etc
+1  A: 

$(: ...) is a little less ugly, but still not good.

Ignacio Vazquez-Abrams
A: 

If the comment is worth making, it probably can go at the end of the line, or on a line on its own. I seldom find a need for within-line comments with code before and after the comment in any language.

Oh, there's one exception, which is the dialect of SQL I usually use which uses '{comments}'. Occasionally, I will write:

CREATE UNIQUE INDEX u1_table ON Table(...);
CREATE {DUPS} INDEX d1_table ON Table(...);

But even that is a stretch.

Jonathan Leffler
+1  A: 

I find it easiest (and most readable) to just copy the line and comment out the original version:

#Old version of ls:
#ls -l $([ ] && -F is turned off) -a /etc
ls -l -a /etc
Dan
A: 

Most commands allow args to come in any order. Just move the commented flags to the end of the line:

ls -l -a /etc # -F is turned off

Then to turn it back on, just uncomment and remove the text:

ls -l -a /etc -F
dave