ruler


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ruler
# 1  
Old 10-19-2005
ruler

Hi,
I remembered that I used the ruler command at the unix prompt.
But I tried to use it again and it says that command not found.
I don't know what had happened.

It's in the command not in VI, right?

Thanks!
# 2  
Old 10-19-2005
I use my own ruler script....

Code:
# ./ruler.sh 50
    5    10   15   20   25   30   35   40   45   50
....|....|....|....|....|....|....|....|....|....|

Is that the sort of thing you want?

Code:
#! /bin/ksh

if [ "$#" -ne "1" ]; then
  echo "usage: `basename $0` width"
  exit 1
fi

if [ "$1" -lt "1" -o "$1" -gt "100" ]; then
  echo "ruler: invalid width entered"
  echo "please enter width between 1 and 100"
  exit 1
fi

# First step
# ==========
# Print char numbers
#
size=$1
i=0
count_cntl=0

while [ "$i" -le "$size" ]
do
  let "count_cntl = $count_cntl + 1"
  if [ "$count_cntl" -eq 5 ]; then
    count_cntl=1
  fi

  if [ "$i" -eq "0" ]; then
    let "i = $i + 1"
    continue
  fi

  mod=$(( $i % 5 ))
  if [ "$mod" -eq "0" ]; then
    echo "${i}\c"
  else
    if [ "$i" -lt "10" ]; then
      echo " \c"
    else
      if [ "$count_cntl" -eq 3 ]; then
         let "count_cntl = $count_cntl + 1"
      else
         echo " \c"
      fi
    fi
  fi
  let "i = $i + 1"
done

echo ""


# Second step
# ===========
# Print ruler itself

size=$1
i=0

while [ "$i" -le "$size" ]
do
  if [ "$i" -eq "0" ]; then
     let "i = $i + 1"
     continue
  fi

  mod=$(( $i % 5 ))
  if [ "$mod" -eq "0" ]; then
    echo "|\c"
  else
    echo ".\c"
  fi

  let "i = $i + 1"
done

echo "\n"

exit 0

Cheers
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using sed to print a ruler

How can I use sed to print rulers of x characters in length on my terminal? For example, I want sed to print a 50-character rule. sed '// p' ?? Thanks! (5 Replies)
Discussion started by: doubleminus
5 Replies
Login or Register to Ask a Question