Bash script

Hi ,
Some one can help me
i need to write a script using while loop to run till the number is postive ie <!= 0

Please try something so we can help on some base.

You don't rely expect people to make the script for you ?!!

Make one by your self, and after we'll help you make it work

#!/bin/bash
a=0
while [ "$a" -ge 0  ]
do
 a=$(($a+1))

 if [ "$a" -le 0 ]
 then
   break
 fi

 echo -n "$a "
done

echo; echo; echo

exit 0

If I understand you correctly what you want is to increment a number until it reaches above 0?

but the code you offered as your attempt will only loop in the while "$a" is already greater than or equal to 0:

a=0
 while [ "$a" -ge 0  ]

Then since "$a" is instantiated as 0 and it matches the first while condition you start incrementing "$a":

a=$(($a+1))

after that increment you are testing if "$a" is less than or equal to 0 and break out of the while loop if it is:

if [ "$a" -le 0 ]
  then
    break
  fi

Essentially you do this:

  1. Set $a = 0
  2. Test is $a is equal or grater than zero
  3. Increment $a by 1 (making it now $a=1)
  4. Test for it to be 0 or less and break if it is
  5. echo $a
  6. Restart while loops with $a equal to 1

This will never break as $a will always be 0 or greater which means it will evaluate to true in the while condition and then it will just echo numbers to screen growing by 1 each time forever (or until you manually kill it).

Try this instead:

#!/bin/bash
a=0
CURR_MIN=$(date +%M |tr -d '0')
BREAK_MIN=$(($CURR_MIN + 1))
while [ "$a" -eq 0 ]
do
  # Set a predictable condition,
  # anything that will change
  # like the minute in the current time
  # (date +%M)
  CURR_MIN=$(date +%M |tr -d '0')
  if [ $CURR_MIN -ge $BREAK_MIN  ]
  then
    a=$(($a+1))
  fi
  echo -e "\$a: $a\nBREAK_MIN: $BREAK_MIN\nCURR_MIN: $CURR_MIN\n-------------------"
done

echo -e "\n\n\n"
exit 0

Now obviously we could just have easily placed a break inside that if statement instead of increment $a. The point was to show a valid way to break if $a is not 0 though.

i don't how to create thread procedure..
Just i want to ask How to search and display name of zero byte file
i have used find command but it is showing complete file path
Thanks

@vivek1489
Please go to the appropriate forum (Shell Programming and Scripting) and click on the "New Thread" button at the top on the left. You really cannot miss that big blue button.

If you create a new thread we will answer.