If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Simple loop help!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-01-11, 15:11
thurft thurft is offline
Registered User
 
Join Date: Sep 2011
Posts: 1
Simple loop help!!

Ok
basically Im stuck at what i believe is something really simple but i just dont ahve a clue how to do it efficiently and properly and i REALLY appreciate some help

Basically i have a loop at which someone has to enter a string of 3 numbers,
I want the code to check that the string is numbers only, check that the numbers have not been already signed to someone else in the users.db file and to restrict the number of numbers to only 3.

and each time the user inputs the number wrong i want it to be allowed to correct and tell why he has to re enter it.

This is the best i could came up with but IM REALLY suck and im at a short UNIX course (1 week) for a job....

Can anyone please tell how do i make the loop properly??

this is the best i could came up with... and i KNOW is crap... but i just dont know best........ I would really appreciate some guidance plz

thanks

Quote:
#!/bin/bash
echo -e "Create a new record\n"

fSID (){
read -p "Please enter staff ID: " cSID
}

fSID

gcSID=$(grep $cSID users.db | cut -d ":" -f1 | tr [":"] [" "])
wcSID=$(echo $cSID | wc -c)

case "$cSID" in
[!0-9]* ) echo -e "The staff ID should contain only digits\n "
sleep 0.5
fSID;;

esac
while [ $wcSID -gt 4 ]; do

read -p "Please enter a value: " cSID
wcSID=$(echo $cSID | wc -c)
echo $wcSID
done
read -p "u passed to stage 2! gratz" st2
Reply With Quote
  #2 (permalink)  
Old 09-01-11, 21:20
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
You have to finish this:

Code:
acceptable=N
while acceptable = N
do
  echo "enter user id \c"
  read user
  if $user passes numeric tests
     acceptable=Y
  fi
  if acceptable = Y
    grep $user user.db
    if $? = ???????
      acceptable=N
   else
     echo $user >>user.db
     echo $user is acceptable, and added to userdb
   fi
done
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On