Need help to Simplfy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to Simplfy
# 1  
Old 11-30-2008
Need help to Simplfy

Code:
while  [[ "$vrfy" != "true" && "$vrfy2" != "true" ]];
    do
            echo "ID format - 000-000-000"
            read -p "Enter Name: " usrnme
            read -p "Enter ID: " id
        if echo $usrnme | grep "^[A-Za-z]" > /dev/null 
            then
                 vrfy="true"
        else
            until [ "$vrfy" = "true" ];
                do
                        echo "Re-enter name"
                           read -p "Enter Name: " usrnme
                            if echo $usrnme | grep "^[A-Za-z]" > /dev/null
                                 then
                                     vrfy="true"
                            fi
                       done
         fi

     if echo "$id" | grep "^[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9]$" > /dev/null
             then
                 vrfy2="true"
         else
         until [ "$vrfy2" = "true" ];
                do
                        echo "format 000-000-000"
                        read -p "Enter ID: " id
                             if echo "$id" |  grep "^[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9]$" > /dev/null
                                 then
                                     vrfy2="true"
                            fi
                    done
        fi      
done

here my portion of my code i having trouble to compress it
i feel that i can do the same task in smaller amount of lines
but i haven't figured out how
# 2  
Old 11-30-2008
Here's a piece of it. Replacing lines 4-19:
Code:
        until [ "$vrfy" = "true" ];  do
                read -p "Enter Name: " usrnme
                echo $usrnme | grep -q "^[A-Za-z]"  &&  vrfy="true"
        done

# 3  
Old 11-30-2008
Hi,

you could use this for the second part. This way you save two external
processes and a number of lines.

Code:
while [[ $vrfy2 != true ]]
do
    if [[ "$id" == [0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9] ]] 
    then 
        vrfy2=true 
    else 
        read -p "Enter ID in format 000-000-000: " id 
    fi
done

HTH Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simplfy

I feel that i can Simplfy this but i am not fully sure how vars1=$(cat vartext | cut -d" " -f9) for word in $vars1 do var2=$(dirname $word) if ]; then ls -l $word ... (9 Replies)
Discussion started by: jafa401
9 Replies

2. Shell Programming and Scripting

simplfy

ls /etc/init.d/rc4.d/ | while read FILE do tput smso echo -n `expr "$FILE" : '\(S.*$\)'` tput rmso echo `expr "$FILE" : '\(K.*$\)'` done this is part of my code i feel that i can simplify this even more but not sure (1 Reply)
Discussion started by: jafa401
1 Replies
Login or Register to Ask a Question