You are not logged in.
Pages: 1
Ok, I have a loop and I want to count the number of times the loop occurs in my script. Every time the loop occurs there is an output. I want during the loop to display 1 - infinite number until the loop stops.
Do you know what I am getting at?
Last edited by haxit (2009-02-13 18:04:37)
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Is this what you mean?
i=0; while true; do let i=$i+1; echo $i; done
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Like this?
i=0
while [ $i -lt 10 ]; do
echo $i
i=$(($i + 1))
done
Offline
Thanks
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Ok, heres another one. I get a list of number in the output, three to be exact. How can I add them all together and divide them by three?
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Ok, heres another one. I get a list of number in the output, three to be exact. How can I add them all together and divide them by three?
can you provide a more specific example?
[23:00:16] dr_kludge | i want to invent an olfactory human-computer interface, integrate it into the web standards, then produce my own forked browser.
[23:00:32] dr_kludge | can you guess what i'd call it?
[23:01:16] dr_kludge | nosilla.
[23:01:32] dr_kludge | i really should be going to bed. i'm giggling madly about that.
Offline
Like this?
i=0
sum=0
amt=0
while [ $i -lt 10 ]; do
if [ $(( $i % 2 )) == 0 ]; then
echo $i
sum=$sum+$i
amt=$(($amt+1))
fi
i=$(($i+1))
done
echo avg = \($sum\)/$amt = $(( ($sum)/$amt ))
Offline
list="1 2 3"
count=0
for number in list; do
count=$(($count + 1))
sum=$(($sum + $number))
fi
# Don't know if bash can do division all that well
awk "BEGIN { print $sum / $count }"
Offline
Ok, so I have this script:
#!/bin/bash
if [ -z "$1" ]; then
echo "Please run like so: 'sh "$0" <highest number on dice>'"
else
WOW=`echo "$1*2" | bc`
for X in 1 2 3; do
ONE=`seq 1 $1 | sort -R | head -1`
TWO=`seq 1 $1 | sort -R | head -1`
HAH=`echo "$ONE+$TWO" | bc`
until [ $HAH -eq $WOW ]; do
ONE=`seq 1 $1 | sort -R | head -1`
TWO=`seq 1 $1 | sort -R | head -1`
HAH=`echo "$ONE+$TWO" | bc`
NUM=`echo "1"`
echo "$HAH" >> probability.log
done
LOL=`cat probability.log | wc -l`
echo "$LOL"
rm probability.log
done
fi
It gives me three outputs, I want to add those outputs and divide them by 3.
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
sum=$(( $1 + $2 + $3 ))
answer=$(echo "${sum}/3" | bc)
echo $answer
EDIT: duh...
echo "($1+$2+$3)/3" | bc
dunno why i broke it up originally.
Last edited by brisbin33 (2009-02-13 17:53:09)
//github/
Offline
sum=$(( $1 + $2 + $3 )) answer=$(echo "${sum}/3" | bc) echo $answer
Wow, why didn't I think of that
Thanks!
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Pipe it to
awk 'BEGIN {s=0;c=0} {s=s+$1; c=c+1} END {print s/c}'
Offline
I don't get what this does. :\
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
This sounds like someones homework...
Offline
This sounds like someones homework...
Nah! Dude I am only in grade 11 and not taking any computer courses. This is something i was discussing with a friend and I said Ill do it on the weekend. Check it out here: http://web.ncf.ca/ey723/scripts/probability.sh
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Pages: 1