Introducing UNIX and Linux |
Introduction to shellsOverview |
Answer to chapter 7 question 5Use
COUNT="" # Use to count to 4
ALLUSERS=$(who -q | head -1) # Get the list of users
for i in $ALLUSERS # Loop through in turn
do
printf "%10s" $i # Print each in width 10
COUNT=$COUNT"x" # Add an "x" to COUNT
if [ "$COUNT" = "xxxx" ] # If 4 "x"s in COUNT
then printf "\n" # terminate the line
COUNT="" # and reset COUNT
fi
done
# At the end, if the final line contains less than
# four columns, that line must be terminated
if [ "$COUNT" != "" ]
then printf "\n"
fi
|
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck