From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Cohen, Andy" Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: how to dynamically add/remove a comment Date: Fri, 10 May 2002 16:15:45 -0400 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <6AF24836F3EB074BA5C922466F9E92E104DD84DF@prince.pc.cognex.com> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Trace: main.gmane.org 1021062964 29234 127.0.0.1 (10 May 2002 20:36:04 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 10 May 2002 20:36:04 +0000 (UTC) Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.20.101]) by main.gmane.org with smtp (Exim 3.33 #1 (Debian)) id 176H7U-0007bH-00 for ; Fri, 10 May 2002 22:36:04 +0200 Original-Received: (qmail 3203 invoked by uid 5); 10 May 2002 20:16:07 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 3195 invoked from network); 10 May 2002 20:16:06 -0000 Original-Received: from unknown (HELO emroute2.cind.ornl.gov) (128.219.159.41) by 0 with SMTP; 10 May 2002 20:16:06 -0000 Original-Received: from emroute2.cind.ornl.gov (LOCALHOST [127.0.0.1]) by emroute2.cind.ornl.gov (PMDF V6.1-1 #39060) with ESMTP id <0GVW00M0NWATJH@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 10 May 2002 16:16:05 -0400 (EDT) Original-Received: from mtvwca1-smrly1.gtei.net (mtvwca1-smrly1.gtei.net [128.11.176.196]) by emroute2.cind.ornl.gov (PMDF V6.1-1 #39060) with ESMTP id <0GVW008BTWAEML@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 10 May 2002 16:15:51 -0400 (EDT) Original-Received: from cognex-cp.cognex.com (cognex-cp.cognex.com [198.232.30.75]) by mtvwca1-smrly1.gtei.net (Postfix) with SMTP id 0FD2B1368F for ; Fri, 10 May 2002 20:15:50 +0000 (GMT) Original-To: "tru64-unix-managers \(E-mail\)" X-Mailer: Internet Mail Service (5.5.2650.21) Xref: main.gmane.org gmane.os.tru64.managers:149 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:149 I sent this earlier but I don't think it came through. Sorry if this is a duplicate but I wanted to make sure I got the summary posted. SUMMARY ======= As always several speedy and very helpful replies. Basically the manner in which shell scripts get processed prevent me prevent accomplishing what I want to using the '# ' as the means to toggle between execution and debug mode. Oisin said: Ignoring control structures such as loops and functions, you are assuming that the shell deals with a command script line by line by first making substitutions, and then deciding whether the line is a comment line, and then running the command. Not so! Rather the conceptual model should be: Remove all explicitly commented lines from file, then deal with the result. So to be able to run in debug mode there were four different ways presented: 1) Alan Davis provide a very thorough elegant 'engineered' approach to this but, at least for now, would require more setup on my part than I feel this project warrants. 2) wrap the commands I wish to toggle in an if - fi statement: if ($1 != 'debug') then compress -v *.dbf fi 3) instead of using a # as the means of preventing execution use 'echo'. This is nice because it not only doesn't execute but it will display the line so when debugging one can determine, if necessary, whether that line was reached or not. Though there was a warning: Note this may not work with compound commands, e.g. $doit command1 && command2 will execute command2 even in debug mode. 4) a couple of suggestions to use the no-op command ":". This worked perfectly. Just toggle between nothing and the ':'. 5) there were suggestions to use 'eval' and to make a 'here' document. I have no experience with either of these techniques. Thank you everybody! Andy ORIGINAL QUESTION ================= Hi, I'm writing a korn-shell script and I want to be able to be able to run it in a 'debug' type mode. That is I want to optionally pass in a parameter (e.g., 'debug') that will force the script to comment out certain lines that I don't want to perform. Without this parameter the lines will execute, with this parameter the lines won't be executed. The script is setup to be run either with or without the parameter ($1). If $1 = 'debug' then a variable (SHELL_DEBUG) is set to '# ' (ksh comment). If $1 is not 'debug' (i.e., absent) then SHELL_DEBUG is set to "" (nothing, null). For the lines that I want to be able to comment out with this parameter I put ${SHELL_DEBUG} at the beginning of the line (e.g., $SHELL_DEBUG ./cp_hb_archlogs_$ORACLE_SID.sh). This part seems to be working ok. The problem is that when run the command line processor doesn't seem to recognize the "# " as a legitimate comment. If I issue 'set -x' I get: + # compress -v *.dbf ./HOT_BACKUPS_734_MULTI_DB.sh[231]: #: not found so the '#' is getting added to the beginning of the line but then an error is generated "#: not found". Am I doing something wrong? Is this even possible? Am I on the right path or is there some other approach I should take (i.e., 'case' or 'if' branching)? Thanks much! Andy =================================================== Andy Cohen Database Systems Administrator COGNEX Corporation (508) 650-3079 Fax: (508) 650-3337 andy.cohen@cognex.com www.cognex.com cell: (617) 470-0034 ===================================================