Path: utzoo!attcan!uunet!ncc!alberta!oha!tony From: tony@oha.UUCP (Tony Olekshy) Newsgroups: comp.unix.questions Subject: Writing a loop in csh (was: file renaming facility). Summary: Easy way to write loops from command prompt in csh. Message-ID: <221@oha.UUCP> Date: 14 May 88 00:17:41 GMT Organization: Olekshy Hoover & Associates Ltd., Edmonton,Alberta,Canada Lines: 18 A discussion of how to rename a set of files from the csh user prompt has recently been carried out in this newsgroup. This is really a specific case of operating over each item in a group with a command. Unfortunately, the csh looping construct is messy and does not admit to the operation of the history mechanism. I use the csh as an interactive shell but use sh for scripts. Since I am therefore familiar with the sh syntax, I use the following looping mechanism from the csh prompt: %sh -cx 'for i in 1 2 3 4 5; do cp /dev/null $i.a; done' %sh -cx 'for file in ?.a; do mv $file `basename $file .a`.b; done' If you know or can learn a little sh syntax, this works like a charm. The -x option gives you a running log of what is going on. History-based editing works unexpectedly well, because the whole looping command is a single string, ie, !!:2 is 'for file in ?.a; do mv $file `basename $file .a`.b; done'