Unix Shell basic loop massive n00b

hey guys
I would really appreciate some help, i need to do a project for a job that requires minimal UNIX scripting and im REALLY stuck

basically Im stuck at what i believe is something really simple but i just dont have 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
-restrict the number of numbers to only 3.

- 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

Code:
#!/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
 
Well first things first your shabang is wrong.

use either:

Code:
#!/bin/sh
for posix sh

or

Code:
#!/usr/bin/env bash

for gnu bash

feel free to peruse the man page with % man [man]sh[/man] to find the syntax for looping
 
FWIW, I found a file which hinted at solutions, saved locally, but it was for perl. Googling its title found over a million results, the first page of results seems directly relevant to your post. So the google search would be
Code:
 recursive shell looping
. Haven't tried the search with quotes around it.
 
The parameters to tr(1) are wrong.

The steps to the loop are out of order. I'd suggest you make a list of what has to happen in order in each pass through the loop.
 
Back
Top