Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Scripting - Looping Query

Status
Not open for further replies.

HHG

Technical User
Nov 8, 2003
68
GB
Hi

Can anyone help please; I have created a simple script which transfers some files into another directory.

I need to put a whole loop around the main body.

Basically..
There will be a file which will hold a number of records.

e.g. number = 127

At the end of the script I need to reset the number to Zero in the file number.

Each time my script runs I want to check if this file has a zero init, if so I don't want it to process the next batch but instead wait. I want to do somthing like;-

if $a = 0
do
not do anything
else
do something.

Not sure which is the best loop to use for this. if, while etc. This is I think basic stuff, but not done scripting for a while. Anyone offer of help would be most appreciated.

Thanks





 
Should work in ksh:
Code:
while [ ! $a = 0 ]
do
   do something
done
 
Thanks for this.

Can there be an else statement on this.

While
do
do somthing
else do
do something
done

If there is can you help with the syntax on this please. Thanks
 
Hi

At this point you should read some manual. Any manual about programming/scripting would be good.

No, usually you can not add [tt]else[/tt] clause to a [tt]while[/tt] statement. But of course, we can not affirm this firmly, while you still not revealed the name of your shell.

Use this as a starting point :
Code:
while :; do

  nr=`cat file_with_number`

  if [ "$nr" -eq 0 ]; then
    wait 10
  else
    # do what you want
  fi

done

Feherke.
 
Thanks Feherke
I have a book infront of me so I managed to get the if else if bit. But the extra bit you have just sent me on while is good so I will use this. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top