Top level TCSH while Loop doen't work


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Top level TCSH while Loop doen't work
# 1  
Old 02-03-2005
Network Top level TCSH while Loop doen't work

Hey guys...

I'm learning some shell scripting on OS X using the tcsh shell.

For some reason... my while loop isn't executing right (or more likely I am doing something wrong.)

Something as simple as this doesn't work:

Code:
#!/bin/tcsh

set g = 0

while ($g <10)

echo "this" $g

@ g = $g + 1

end

By doesn't work, I mean it goes through the first time and then stops.

If I type it in to the terminal it works fine. But if I write it in a text editor (BBEdit) and save it as a script, then execute (after making it executable) it only goes through the first iteration.

The WEIRDEST part is that if I nest a while loop inside of it with the exact same syntax, the inner loop works correctly, while the outer loop still only goes through once.

Little help?

Robert
# 2  
Old 02-04-2005
Well, your code works under Solaris tcsh with no problem.

Are you getting any kind of error? Try the following - maybe it's dumping out and you aren't getting any error message.

Code:
#!/bin/tcsh

set g = 0
echo "should be zero - $g"
while ($g <10)

echo "this" $g

@ g = $g + 1
echo "should be plus 1  - $g"
end
echo "end of script"

# 3  
Old 01-23-2009
New line or some line is required after the "end" statement

I ran the script on Solaris and on Linux it worked with the statement 'echo "end of script"' at the end. It also worked even if this statement was commented. So I deleted the words in that line leaving out a blank line after end statement. The script still worked. But only when I remove the last line and leave nothing after end it stops looping.
#!/bin/tcsh
set g = 0
while ($g <10)
echo "this" $g
@ g = $g + 1
echo "should be plus 1 - $g"
end #Doesn't work


#!/bin/tcsh
set g = 0
while ($g <10)
echo "this" $g
@ g = $g + 1
echo "should be plus 1 - $g"
end
#Does work. Notice that this introduces a new line character after end above
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Top 10 Users in mount level

Hi Members, I'm new to unix. Could you help me in solving my issue. My requirement is I need to pull Top 15 users in every mount. I could able to get the mount level information but I couldn't able to pull the top users in every mount. I see in every mount I could see a lot of nested... (3 Replies)
Discussion started by: UBEE
3 Replies

2. UNIX for Beginners Questions & Answers

Bash script - Remove the 3 top level of a full path filename

Hello. Source file are in : /a/b/c/d/e/f/g/some_file Destination is : /d/e where sub-directories "f" and "g" may missing or not. After copying I want /a/b/c/d/e/f/g/file1 in /d/e/f/g/file1 On source /a is top-level directory On destination /d is top-level directory I would like... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

How to get top level parent directory

Hi All, I have a directory like this: /u01/app/oracle/11gSE1/11gR203 How do i get the top level directory /u01 from this? Tried dirname and basename but dint help. I can this using echo $ORACLE_HOME | awk -F"/" '{print "/"$2}'. But I am trying to find out if there is a better way of doing it... (4 Replies)
Discussion started by: nilayasundar
4 Replies

4. Shell Programming and Scripting

Problem with File Names under tcsh loop

Hello, I have a question regarding file naming under a loop in tcsh. I have the following code: #!/bin/tcsh foreach file (test/ProteinDirectory/*) # The * is a bunch of ProteinFile1, ProteinFile2, ProteinFile3, etc. sh /bioinfo/home/dgendoo/THREADER/pGenThreader.sh $file $file ... (4 Replies)
Discussion started by: InfoSeeker
4 Replies

5. Shell Programming and Scripting

Help needed removing two top level folders from path

Hi, I am trying to use either awk or sed to drop the first two folders in a path. So if I had path /folder1/folder2/folder3/folder4.... I need to drop folder1&2, so the new path would be /folder3/folder4... If folder1 and folder2 were the same all the time, this would be easy. But... (4 Replies)
Discussion started by: robertinohio
4 Replies

6. Shell Programming and Scripting

tcsh I can't get script to work :(

I have an export utility that exports documents from the native file to text. This is the way I would run it from the command line: expage "file" > "file.txt I am trying to loop through all the documents in the directory and expage them, here is the code: #!/usr/bin/env tcsh foreach file... (8 Replies)
Discussion started by: Fred Goldman
8 Replies

7. Shell Programming and Scripting

How to exclude top level directory with find?

I'm using bash on cygwin/windows. I'm trying to use find and exclude the directory /cygdrive/c/System\ Volume\ Information. When I try to use the command below I get the error "rm: cannot remove `/cygdrive/c/System Volume Information': Is a directory. Can someone tell me what I am doing... (3 Replies)
Discussion started by: siegfried
3 Replies

8. Shell Programming and Scripting

Is there any way to set env variable in top level Makefile and unset when done

Hello I have compilation directory structure the top level Makefile is the one that contains all the sub directories I want to set in this Makefile env variable say : setenv OPTIMIZATION_LEVEL "1" and when all the sub directories done compiling it will set this variable to different lavel... (0 Replies)
Discussion started by: umen
0 Replies

9. Shell Programming and Scripting

TCSH.need help.take input during a while/end loop

I am writting a script in csh and I am blanking out on how I code in the ability to process user input in the middle of a while/end loop. while(1) args.. end it is a simple script, and I want to add hotkey functions, like q to quit, z to zero counters, etc.. Google has not been very... (1 Reply)
Discussion started by: seg
1 Replies
Login or Register to Ask a Question