The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
tail | grep lagging badly WasabiVengeance Shell Programming and Scripting 3 04-22-2008 07:53 PM
Number count per number ranges shirleyeow Shell Programming and Scripting 5 12-19-2007 04:06 AM
Badly placed ()'s. - error amitrajvarma Shell Programming and Scripting 3 10-12-2007 05:40 AM
to print number one less than actual number cdfd123 Shell Programming and Scripting 4 09-06-2007 07:56 AM
New to it all, But i wanna script really badly!!! TheNewGuy Shell Programming and Scripting 3 07-03-2004 11:33 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 06-05-2008
ROOZ ROOZ is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 48
for:badly formed number

Hi,
I am doing the following but it complains and says "for:badly formed number"
does anyone know why?

#!/bin/tcsh
foreach(....)
............

set depth=64
set width=23
if ($depth==64) then
echo "if"
set addr_bits=5
else
echo "else"
endif

echo "addr_bits:$addr_bits"
echo "depth:$depth"
echo "width:$width"

end


Guys please note that i need to use #!/bin/tsch because foreach will not work without it. becuase the if statement works fine just the way it is if i don't use #!/bin/tsch and i do the following
depth=64
if ($depth==64) then
echo "if"
addr_bits=5
else
echo "else"
endif

the problem occurs when i use #!/bin/tcsh
  #2 (permalink)  
Old 06-05-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
i) please use the code markup tag and indention for better readability
ii) there's no single for in your snippet which depends on numbers
iii) it would be interesting to know what's inside foreach(...)
  #3 (permalink)  
Old 06-05-2008
ROOZ ROOZ is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 48
here is the actual code. note that testing1 consist of couple of line lets say asdaskljl64x3sdfsd is the first line of the testing1 file
#!/bin/tcsh
foreach filename (`cat testing1`)
set string=$filename
set depth=`echo "$string" | sed -e 's/^[^0-9]*\([0-9][0-9]*\).*/\1/'`
set width=`echo "$string" | sed -e 's/.*\([0-9][0-9]*\)[^0-9]*$/\1/'`

if ($depth==64) then

set addr_bits=5
endif

echo "addr_bits:$addr_bits"
echo "depth:$depth"
echo "width:$width"

end
  #4 (permalink)  
Old 06-05-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
error message does (in my eyes, generally I don't use ksh) not match the code.

Only point that matches numbers in any way:

However: Bourne-comment (mostly be the same on ksh): use
Code:
if ( "$depth" -eq "64") then
instead of
Code:
if ($depth==64) then
-eq => numerical comparison
"" => prevents problems when $depth is empty
Closed Thread

Bookmarks

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 03:11 PM.


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