# UNIX or Linux code

**URL:** <https://forums.speedlife.net/t/unix-or-linux-code/41951>\
**Category:** NYSpeed Off Topic\
**Created:** [January 16, 2008, 3:45pm UTC](https://forums.speedlife.net/t/unix-or-linux-code/41951 "2008-01-16T15:45:31Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![Matt\_Danger](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/matt_danger/32/4981_2.png) [@Matt\_Danger](https://forums.speedlife.net/u/Matt_Danger)\
**Post date:** [January 17, 2008, 12:37pm UTC](https://forums.speedlife.net/t/unix-or-linux-code/41951/23 "2008-01-17T12:37:21Z")

</div>

```auto
#!/bin/ksh
# Question 1
COUNT=0
while read NUM; do
        # Set initials
	if [$COUNT -eq 0]; then
		HIGHEST=$NUM
		LOWEST=$NUM
		SUM=$NUM
	fi
	# If 999 is entered, break out
	if [$NUM -eq 999]; then
		break
	else
		# See if inputted number is the highest number
		if [$NUM -gt $HIGHEST]; then
			HIGHEST=$NUM
		fi

		# See if inputted number is the lowest number
		if [$NUM -lt $LOWEST]; then
			LOWEST=$NUM;
		fi
		# Calculate sum
		SUM=$(($SUM+$NUM))
	fi
	COUNT=$(($COUNT+1))
done
AVERAGE=$(($SUM/$COUNT))
echo "Highest number: $HIGHEST"
echo "Lowest number: $LOWEST"
echo "Sum of the numbers: $SUM"
echo "Average of the numbers: $AVERAGE"

```

```auto
#!/bin/ksh
# Question 2
RAN=$((RANDOM%60))
COUNTER=1
echo -n "I've guessed a number between 0-60, what is it? "
while read GUESS; do
	if [$GUESS -eq $RAN]; then
		break;
	else
		echo
		if [$GUESS -lt $RAN]; then
			echo -n "Nope, try a higher number: "
		else
			echo -n "Nope, try a lower number: "
		fi	
	fi
	COUNTER=$((COUNTER+1))
done
echo; echo "Yep, good job! It took you $COUNTER tries to guess correctly."

```

```auto
#!/bin/ksh
# Question 3
echo -n "Enter a number: "; read NUM
echo -n "Enter 1 to count up to $NUM and 2 to count down to 0: "; read CHOICE
case $CHOICE in
	1)	COUNTER=0
		while [$COUNTER -le $NUM]; do
			echo $COUNTER
			COUNTER=$(($COUNTER+1))
		done ;;

	2)	while [$NUM -ge 0]; do
			echo $NUM;
			NUM=$(($NUM-1))
		done ;;
esac

```

---

_[View the full topic](https://forums.speedlife.net/t/unix-or-linux-code/41951)._
