willisoften Posted March 28, 2004 Report Share Posted March 28, 2004 I'm busy revising for a test on shell basics tomorrow morning so a prompt reply would be appreciated. I'm running through some excercises and while attempting to get a foreach loop running the shell seems to be telling me there is no such thing. csh keeps coming up foreach? while bash just doen't do anything at all. Comments please. Quote Link to comment Share on other sites More sharing options...
willisoften Posted March 28, 2004 Author Report Share Posted March 28, 2004 OK some more information: apparently there is no foreach in korn / bash only in the cshell foreach? is the prompt to type the next instruction on typing end at the foreach? prompt the loop should execute. Why it's not working I have no idea. Quote Link to comment Share on other sites More sharing options...
aru Posted March 28, 2004 Report Share Posted March 28, 2004 (edited) To my knowledge bash has no 'foreach' command at all. But zsh does. \$ foreach dir (*/) foreach> echo $dir foreach> end Mail/ RCS/ bin/ etc/ evolution/ foo/ tmp/ var/ Ofcourse bash can do the same with its for builtin: ~$ for dir in */ > do echo $dir > done bin/ etc/ evolution/ foo/ Mail/ RCS/ tmp/ var/ Is that what are you looking for. [Edited] I had to go in a hurry when I was writing this post so I half posted it. Now I've completed the bash part ;) Edited March 28, 2004 by aru Quote Link to comment Share on other sites More sharing options...
willisoften Posted March 28, 2004 Author Report Share Posted March 28, 2004 Theres a foreach in the c shell I can now make it work at the prompt but it won't work, as yet, when written into a script. A little annoying but not the ned of the world it's only one excercies out of about 50. ned ? I think I meant end but the ned of the world sounds pretty good! :D Quote Link to comment Share on other sites More sharing options...
Cannonfodder Posted March 29, 2004 Report Share Posted March 29, 2004 When you run the script is it running a c shell session? Quote Link to comment Share on other sites More sharing options...
willisoften Posted March 30, 2004 Author Report Share Posted March 30, 2004 I've done the test and there was no foreach question on it. Everything was OK but there was one question I couldn't do (posted it elswhere) We were expected to use the cshell. the syntax I have goes foreach colour (red green blue yellow) echo a colour $colour end You type the first statement at the $ prompt after you hit enter then each succeeding statement at a special foreach ? prompt it executes at end <enter> According to the student demonstrator you use the foreach in live terminal sessions not in scripts. He could be right. though that wasn't what the original tutorial sheet suggested. Is there a good book on bash scripting? Web tutorials abound, but I'd like something that would lie on a desk. thanks to all Will Quote Link to comment Share on other sites More sharing options...
aru Posted March 31, 2004 Report Share Posted March 31, 2004 http://www.tldp.org/LDP/abs/abs-guide.pdf http://www.gnu.org/software/bash/manual/ ;) Quote Link to comment Share on other sites More sharing options...
willisoften Posted March 31, 2004 Author Report Share Posted March 31, 2004 Thanks aru. How are Valencia doing this season? Haven't heard much about them on British television. Quote Link to comment Share on other sites More sharing options...
aru Posted April 1, 2004 Report Share Posted April 1, 2004 You're wellcome About Valencia, I'm quite happy, we are second, just one point behind real madrid even after the scandalous match between both teams (well exaclty Valencia versus real madrid + referee) Amunt VALENCIA!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.