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
foreach loop + 2 variables JamesGoh Shell Programming and Scripting 3 06-04-2008 03:36 AM
using foreach loop sam4now Shell Programming and Scripting 6 04-26-2008 11:22 AM
foreach loop abch624 Shell Programming and Scripting 1 03-19-2008 09:34 PM
Foreach loop haze21 Shell Programming and Scripting 4 11-16-2007 03:11 AM
foreach loop question clipski UNIX for Dummies Questions & Answers 7 12-22-2005 01:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish 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
foreach loop

Hi everyone
Does anyone know what is wrong with this script. i keep getting errors
foreach filename (`cat testing1`)
set string=$filename
set depth=`echo "$string"
echo $depth
end

the error is the following
testing: line 1: syntax error near unexpected token `('
testing: line 1: `foreach filename (`cat testing1`)'

I would appreciate it
  #2 (permalink)  
Old 06-05-2008
ROOZ ROOZ is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 48
ok guys now it works but it only does the echo command once and displaying the first line, can you guys tell me why this doesn't happen for all of the input line of the file testing1
  #3 (permalink)  
Old 06-05-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
check the set depth line

Code:
set depth=`echo "$string"
It looks like you are missing a `
Personally, I like setting a variable such like

Code:
depth=$(echo "$string")
The command is now inside ( ) and less chance of missing a special character.
  #4 (permalink)  
Old 06-05-2008
ROOZ ROOZ is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 48
thx for the response but i figured out the problem. the file was saved not including "END" at the end of the file(by not pressing ENTER after typing end).
that was the only problem but a hard one for me to capture.
Sponsored Links
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 08: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