The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 03:28 PM
Commenting lines rolex.mp UNIX for Dummies Questions & Answers 2 02-21-2007 04:54 AM
Want to execute rest of the script after the file is ready ... csaha Shell Programming and Scripting 5 09-25-2006 05:04 AM
how to execute C code in linux machine rajan_ka1 Shell Programming and Scripting 3 06-29-2006 06:26 AM
how 2 execute conbal code in unix sushil_d10 Shell Programming and Scripting 1 05-04-2005 09:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-01-2008
Yamini Thoppen Yamini Thoppen is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
How to execute the rest of the code after commenting multiple lines?

Hi,

As I have seen in this forum how to comment multiple lines in the script, but it does not work properly for me.
It is blocking the code but it does not execute the rest of the codes.

This is my code

#! /usr/bin/ksh
month='date +"m%"'

: << Comments Block
if [ "$month -eq 3 ] || [ "$month -eq 6 ]
then
echo "inc = 1"
else
echo "inc = 2"
fi
-- End Comments Block

case $month in
3|6|9|12) echo "Yes";;
*) echo "No";;
esac
echo "This is the last line"


My query is after the comments block, it does not execute the case statement. Can you pls explain it?
  #2 (permalink)  
Old 01-01-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,938
I strongly urge you to use the traditional # method of commenting out shell
script code.

That being said, the problem with your block comment trick is your invalid
syntax for here documents.


Code:
: <<COMMENTBLOCK
if [ "$month -eq 3 ] || [ "$month -eq 6 ]
then
echo "inc = 1"
else
echo "inc = 2"
fi
COMMENTBLOCK

  #3 (permalink)  
Old 01-01-2008
Yamini Thoppen Yamini Thoppen is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
Thanks - But still it does not work.

Quote:
Originally Posted by fpmurphy View Post
I strongly urge you to use the traditional # method of commenting out shell
script code.

That being said, the problem with your block comment trick is your invalid
syntax for here documents.


Code:
: <<COMMENTBLOCK
if [ "$month -eq 3 ] || [ "$month -eq 6 ]
then
echo "inc = 1"
else
echo "inc = 2"
fi
COMMENTBLOCK
Hi Murphy,
Thanks for your reply.

After trying with your sample code, it does not work for me. I dont know what might be the problem.
  #4 (permalink)  
Old 01-01-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
It looks like there is some confusion here.
What fpmurphy is trying to say is that you need to comment out the lines (if needed) that don't need to be executed using # sign, like this:


Code:
#  :<<COMMENTBLOCK
# if [ "$month -eq 3 ] || [ "$month -eq 6 ]
# then
# echo "inc = 1"
# else
# echo "inc = 2"
# fi
# COMMENTBLOCK


In case you are trying to use a HERE document, as suggested you need to get rid of the colon : in front of the sign <<, and no space at the final COMMENTBLOCK :

Quote:
<<COMMENTBLOCK
if [ "$month -eq 3 ] || [ "$month -eq 6 ]
then
echo "inc = 1"
else
echo "inc = 2"
fi
COMMENTBLOCK
So if you need those lines commented out you need to use the first code.

If you are trying to achieve something else with your script, then you need to look in your script and change it accordingly, or post here what are you trying to achieve.
  #5 (permalink)  
Old 01-01-2008
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
if [ "$month -eq 3 ] || [ "$month -eq 6 ]
Your quotes are open.
  #6 (permalink)  
Old 01-01-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
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
  #7 (permalink)  
Old 01-02-2008
Yamini Thoppen Yamini Thoppen is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
sorry ..Typing mistake

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

This is my mistake.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0