How to execute the rest of the code after commenting multiple lines?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to execute the rest of the code after commenting multiple lines?
# 8  
Old 01-02-2008
sorry ..Typing mistake

Quote:
Originally Posted by porter
Your quotes are open.
Hi DRL

This is my mistake.
# 9  
Old 01-02-2008
This should work....

Code:
cat >/dev/null <<IGNORE
asas
das
d
as
das
d
as
IGNORE

# 10  
Old 01-02-2008
Thanks for your reply.

Quote:
Originally Posted by drl
Hi.

A few comments. First, there is a "quoted" string feature in the shells for HERE documents. The use prevents evaluation of everything up to the closing string, including unclosed quotes, variable issues, etc.

Second, ksh does a good job of diagnosing a missing, closing, matching HERE document string -- bash (2 & 3) simply stop.

A ksh example:
Code:
#!/usr/bin/env ksh

# @(#) s1       Demonstrate quick method to render code block inoperable.

set -o nounset
echo

debug=":"
debug="echo"

## The shebang using "env" line is designed for portability and
#  demonstrations. For higher security, use:
#
#  #!/bin/ksh -

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version ksh

echo
echo " Commands before commented-out block."

: <<'EOF'
garbage
junk
worthless
utterly without merit
" crud inside of double quotes "
' debris inside single quote '
" mess inside unmatched double-quotes
' detritus inside an unmatched single-quote pair
...
and so on.
EOF

echo
echo " Commands after  commented-out block."

echo
echo " Failed block quote due to unmatched HERE stings:"

echo
echo " Commands before commented-out block."

: <<'MISSING'
more junk
OOPS!

echo " Commands after  commented-out block."

exit 0

producing:
Code:
% ./s1

(Versions displayed with local utility "version")
pdksh 5.2.14 99/07/13.2

 Commands before commented-out block.

 Commands after  commented-out block.

 Failed block quote due to unmatched HERE stings:

 Commands before commented-out block.
./s1[53]: here document `MISSING' unclosed

I don't use ksh for reasons of availability (my shebangs almost always use simple "sh"), but in this case ksh is superior ... cheers, drl
Hi DRL,

Thanks for you explanation. But for me it is bit confusing, since i am not aware of the sh. i am using ksh only. Still i will try to understand this code.

Thanks
Yamini.
# 11  
Old 01-02-2008
Thanks Porter

Quote:
Originally Posted by porter
This should work....

Code:
cat >/dev/null <<IGNORE
asas
das
d
as
das
d
as
IGNORE

Hi Porter,

What exactly does this code? I tried and I didnt get anything. Can you pls explain breifly for me?

Thanks
Yamini.
# 12  
Old 01-02-2008
Smilie

You were not supposed to get anything - that was the idea.

Anyway, read this:

SHELLdorado - Shell Tips & Tricks (Programmer)
# 13  
Old 01-02-2008
Hi Yamini,

I still believe there is some confusion in your explanation, because you haven't explained what you are trying to do with your script, give a certain message, execute a command, etc ...

If you only need to ( block) comment lines 5 - 12 out, then that's pretty easy, either use # sign as suggested, or porter's way, or the best way : delete lines 5 - 12 .

It's simply not enough saying script doesn't work. First what are you trying to achieve with your script, besides the point of blocking lines 5 -12 ? Post your script if needed.

I got no problem running happily the following script in my linux machine,( no ksh available, should be the same though ! ).

Code:
#!/bin/bash

month=`date +"%m"`
echo "This is $month month"

echo "
        3,6,9,12 ) Yes, time to go   on vacations 
              
        other months ) No,  I'd better go on vacations again !"
              
echo "Enter month"
read month




case $month in
 3|6|9|12) echo "Yes, time to go on vacations"

    ;;

 *) echo "No, I'd better go on vacations again !"
   
  ;;

 esac

 echo "This is the last line"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Javascript to check field is empty then execute rest of script

I have found this bit of code that nearly does what I want. Basically 3 input fields, I want to copy t2 to t3 as it's typed but only if t1 contains data AND t3 is empty: <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="text" id="t3" /> <script> var t2 =... (4 Replies)
Discussion started by: barrydocks
4 Replies

2. Shell Programming and Scripting

Commenting Multiple lines using Shell Script

I have an xml file which has following code : <abc-ref> <abc-name>abc.efg.hij.klm</abc-name> </abc-ref> I want to comment this whole section out and I have written the following script : (where "hij" is unique string in the file) TEMPFILE=replaceYY.tmp file=hello.xml sed -n... (6 Replies)
Discussion started by: Dish
6 Replies

3. Shell Programming and Scripting

perl: Help with commenting out specific lines

Hi I'm trying to comment out specific lines from /etc/fstab file, for simplicity I'm trying to use perl one liner but it errors out, Below is the Perl oneliner I'm using, perl -wlp -i -e 'BEGIN{$flag=0}if (!/root/) && (!/boot/) && (!/tmpfs/) ) {$flag =1;} elsif (/^$/) {$flag=0} if ($flag)... (2 Replies)
Discussion started by: mbak
2 Replies

4. UNIX for Dummies Questions & Answers

Commenting multiple lines

Hi, Can anyone let me know how to comment multiple lines in VI editor? Many thanks. Regards, Venkat. (3 Replies)
Discussion started by: venkatesht
3 Replies

5. Shell Programming and Scripting

Commenting lines in Shell script

Hi All, I know we can comment by using "#" .... I want to know... is there any way to comment a whole big script easily.... In a file i need to comment more than 15 lines ........ and check the script and un comment back. I am learning VI now so its taking lot of time to comment and un... (4 Replies)
Discussion started by: firestar
4 Replies

6. Shell Programming and Scripting

commenting out lines between two delimiters

Hi All, I am struggling to get my head around the following issue. I am having to comment out lines between two delimiters by placing an asterix in position 7 but retain all lines in the file and in the same order. so for example a file containing: ... ... DELIM1 ... ... DELIM2... (2 Replies)
Discussion started by: Bruble
2 Replies

7. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

8. Shell Programming and Scripting

Commenting lines

Hi can any body pls help me : I have a file Which Content is like following: p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog ca:3:respawn:/opt/GoldWing/currentPM/local/critagt > /dev/msglog 2<>/dev/msglog ca:3:respawn:/opt/GoldWing/currentPM/local/startcia.sh... (2 Replies)
Discussion started by: Aditya.Gurgaon
2 Replies

9. UNIX for Dummies Questions & Answers

Commenting lines

How to comment a set of lines in a script? we use # to comment a single line , is there ant other cmd to comment a block? (2 Replies)
Discussion started by: rolex.mp
2 Replies

10. Shell Programming and Scripting

Want to execute rest of the script after the file is ready ...

Hi All I have a requirement like, where a file gets generated in a particular dir and once the file is ready and available then I want to execute rest of the script, because untill and unless the file exists and is available there is no use of running rest of the commands in that script. ... (5 Replies)
Discussion started by: csaha
5 Replies
Login or Register to Ask a Question