simple count script outputting mass errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple count script outputting mass errors
# 1  
Old 03-09-2008
simple count script outputting mass errors

script outputting [: 100: missing ] cant find anything wrong with the script either... :[

Code:
#!/bin/sh
#count execution script

time=0

while [ $time -le 1000 ]
do 



if [ $time -le 100 ]
  then
  time=`expr $time + 1`
  if [ $time = 100 ]
    then
    echo "The current tick is 100"
  fi
fi

if [ $time -gt 101 -le 200]
  then
  if [ $time = 200 ]
  time=`expr $time + 1`
    then
    echo "The current tick is 200"
  fi
fi

if [ $time -gt 201 -le 300]
  then
  time=`expr $time + 1`
  if [ $time = 300 ]
    then
    echo "The current tick is 300"
  fi
fi

if [ $time -gt 301 -le 400]
  then
  time=`expr $time + 2`
  if [ $time = 400 ]
    then
    echo "The current tick is 400"
  fi
fi

if [ $time -gt 401 -le 500]
  then
  time=`expr $time + 2`
  if [ $time = 500 ]
    then
    echo "The current tick is 500"
  fi
fi

if [ $time -gt 501 -le 600]
  then
  time=`expr $time + 2`
  if [ $time = 600 ]
    then
    echo "The current tick is 600"
  fi
fi

if [ $time -gt 601 -le 700]
  then
  time=`expr $time + 5`
  if [ $time = 700 ]
    then
    echo "The current tick is 700"
  fi
fi

if [ $time -gt 701 -le 800]
  then
  time=`expr $time + 5`
  if [ $time = 800 ]
    then
    echo "The current tick is 800"
  fi
fi

if [ $time -gt 801 -le 900]
  then
   if [ $time = 900 ]
    then
  time=`expr $time + 5`
    echo "The current tick is 900"
  fi
fi

if [ $time -gt 901 -le 1000]
  then
   if [ $time = 1000 ]
    then
    echo "The current tick is 1000"
  fi
fi

done

# 2  
Old 03-09-2008
There are numerious errors in your code. The error you showed us relates to the fact that you are not putting a space in front of all the ']''s associated with if statements.

Furthermore, your logic is wrong. Check out the following
Code:
#!/bin/sh
#count execution script

time=0

while [ $time -le 1000 ]
do

  time=`expr $time + 1`

  if [ $time = 100 ]
  then
       echo "The current tick is 100"
  fi
  if [ $time = 200 ]
  then
     echo "The current tick is 200"
  fi
  if [ $time = 300 ]
  then
     echo "The current tick is 300"
  fi
  if [ $time = 400 ]
  then
     echo "The current tick is 400"
  fi
  if [ $time = 500 ]
  then
     echo "The current tick is 500"
  fi

  if [ $time = 600 ]
  then
     echo "The current tick is 600"
  fi
  if [ $time = 700 ]
  then
     echo "The current tick is 700"
  fi
  if [ $time = 800 ]
  then
     echo "The current tick is 800"
  fi
  if [ $time = 900 ]
  then
     echo "The current tick is 900"
  fi
  if [ $time = 1000 ]
  then
     echo "The current tick is 1000"
  fi
done

Note that this can be simplified even further to

Code:
#!/bin/sh
#count execution script

time=0

while [ $time -le 1000 ]
do

  time=`expr $time + 1`
  tick=`expr $time % 100`

  if [ $tick = 0 ]
  then
       echo "The current tick is $time"
  fi

done

and if we really wanted too, we could eliminate a couple of more lines of code.
# 3  
Old 03-09-2008
I looked over my code and i had serveral instances where there was a ] directly after a numerical value. thanks for pointing that out, and yes this script was an early one with serveral errors. Got it to work thanks to your help, the shorthand version blew me away, but i wasnt looking for simplicity in this excersise just repetiton so i can get used to the format etc etc..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple question about charecter count

Hi, I have collection of letters in a column such as: AA5678 AA9873434 .. .. I am trying to find the number of charecters in each. "echo "AA5678"|wc -c 7----------------> why does it give 7 instead of 6? (6 Replies)
Discussion started by: kvosu
6 Replies

2. Shell Programming and Scripting

Outputting Errors to a Log file

Good Morning, Every so often, I have copy scripts that to don't complete, but I don't immediately know why. It usually ends up being a permissions issue or a length issue. The scripts edit a log file, so I'd like to include any copy errors/issues in that file to check if the copies... (4 Replies)
Discussion started by: Stellaman1977
4 Replies

3. Shell Programming and Scripting

Count number of errors within logs for last 6 months

I have directory /test/logs which has multiple logs: audit.log audit.log.1 audit.log.2 audit.log.3 audit.log.4 audit.log.5 audit.log is current log file and audit.log.X are archive log files. I need to search within these log files and count word "error-5" logged within last 6 months... (4 Replies)
Discussion started by: djanu
4 Replies

4. Shell Programming and Scripting

line count with if /else - syntax errors

this is the script: ps -ef|grep "x_jobstat 10 v001" > jobstatv001.txt ps -ef |grep "x_jobserver 10 v001" >> jobstatv001.txt #Sample text - each line preceded by 4 spaces # root 133064 102986 0 08:49:28 pts/6 0:00 grep x_jobstat 10 v001 # root 137550 1 0 Nov 08 - 0:28... (6 Replies)
Discussion started by: kwalkner
6 Replies

5. Shell Programming and Scripting

Simple script to count files

Hello, I am new to shell scripting and I need your help. I have found similar scripts in the forum but I need further assistance. I am building a script to use hourly in cron to mailx me if the number of files in a path is less than e.g 100 I have started with the following: #!/bin/sh... (2 Replies)
Discussion started by: drbiloukos
2 Replies

6. UNIX for Advanced & Expert Users

Truncation Occurs When Outputting Shell Script to stderr

Operating System: Solaris 10, Shell We are outputting the results of our scripts to the stderr file. However we have encountered a problem where some of the lines in the file are truncated. Is there a way to increase the terminal or column size within the script so that this does not... (4 Replies)
Discussion started by: fazzasx
4 Replies

7. Shell Programming and Scripting

Script Assistance - Outputting to file with Awk

I'm trying to take a list of domains, find out the MX resolve it to IP then find out what the NS is and output the contents to a new file. The only problem i'm having is when checking the Ip or host of the MX i can only get it to print the column with the MX record and the results of the host... (1 Reply)
Discussion started by: spartan22
1 Replies

8. Shell Programming and Scripting

bash script to rename in mass

Basically, I have a huge amount of files (ripped audiobooks) that all have the same garbage in their filenames. I'm wondering how to go about writing a bash script to mass rename them. Example filenames as they stand now: The First CD - 1x01 - Title 1.mp3 The First CD - 1x02 - Title 2.mp3... (4 Replies)
Discussion started by: audiophile
4 Replies

9. Shell Programming and Scripting

expr not outputting properly.. bsd sh script

When i run sh -x test.sh, expr outputs x=expr $x + 1 instead of doing the arithmetic.. been working on this overnight.. and its being a pain in the arse if you ask me.. :confused::confused: #!/bin/sh #script for downloading numerical filenames chap=1 p=1 count=0 x=1 while do if ... (2 Replies)
Discussion started by: aspect_p
2 Replies

10. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies
Login or Register to Ask a Question