upper case vs lower case ****newbie*****

upper case vs lower case ****newbie*****

Post by rishi sanka » Sun, 03 Nov 2002 10:26:33



hey guys......thanks for the help.....
now i need to input a variable so that whether the user inputs upper or
lower case it will accept it
hence  this will work for "Q" but not for "q" ............. anyone wanna
help out .......... thanks again

read COIN_VAR
if [ $COIN_VAR = "Q" ];then                                         #1st If
statement
  echo "$Q_MESS,
         You have deposited $Q_AMT cents. Please insert `expr 50 - $Q_AMT`
more cents"
else

 
 
 

upper case vs lower case ****newbie*****

Post by Chris F.A. Johnso » Sun, 03 Nov 2002 10:36:43



> hey guys......thanks for the help.....
> now i need to input a variable so that whether the user inputs upper or
> lower case it will accept it
> hence  this will work for "Q" but not for "q" ............. anyone wanna
> help out .......... thanks again

> read COIN_VAR
> if [ $COIN_VAR = "Q" ];then                                         #1st If
> statement
>   echo "$Q_MESS,
>          You have deposited $Q_AMT cents. Please insert `expr 50 - $Q_AMT`
> more cents"
> else

       if [ "$COIN_VAR" = "Q" -o "$COIN_VAR" = "q"  ];then

   or

       case $COIN_VAR in
          Q|q) echo "$Q_MESS, ...."
               ;;
          *) ;;   ## otherwise...
       esac

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

upper case vs lower case ****newbie*****

Post by Bit Twiste » Sun, 03 Nov 2002 10:41:08



> hey guys......thanks for the help.....
> now i need to input a variable so that whether the user inputs upper or
> lower case it will accept it
> hence  this will work for "Q" but not for "q" ............. anyone wanna
> help out .......... thanks again

> read COIN_VAR

man tr
Maybe you could use tr to translate q to Q
Quote:> if [ $COIN_VAR = "Q" ];then                                         #1st If
> statement
>   echo "$Q_MESS,
>          You have deposited $Q_AMT cents. Please insert `expr 50 - $Q_AMT`
> more cents"
> else

 
 
 

upper case vs lower case ****newbie*****

Post by rishi sanka » Sun, 03 Nov 2002 11:06:08


thanks guys..... i dont know the switches....hehehe
right now i am trying to output to a variable --- my loop is below.... i am
trying to have  the moaunt write to $MONEY.....
i dont know what command to use hence when i type Q or R or D to represent
money... i want to update money ...i dont know if you guys can see what i am
trying to do....
basically.... to buy a can of pop at 50cent --i have to iterate the loop ...
arggghhhh i hate learning frmo scratch....
but if you guys have any ideas to help-- it would be really aprpeciated :)
rishi

# START of concurrent IF-THEN statements to ascertain which coin was used
# Enter coin sequence, either Quarter (Q) , Dime (D) , Nickel (N) , or Coin
Return (R)
# This loop also contains IF-THEN statements that will tell you how much
change you must put
# Nested While Loop to repeat coin input

while [ $MONEY -lt 50 ]                                             #Start
of WHILE LOOP
do

echo " "
echo "Please enter a coin (QDN) or request your change back (R) : "
read COIN_VAR
if [ $COIN_VAR = "Q" -o $COIN_VAR = "q"  ];then                 #1st If
statement
  echo "$Q_MESS,
         You have deposited $Q_AMT cents. Please insert `expr 50 - $Q_AMT`
more cents"
else
if [ $COIN_VAR = "D" -o $COIN_VAR = "d"  ];then                  #2nd IF
statement
 echo "$D_MESS,
         You have deposited $D_AMT cents. Please insert `expr 50 - $D_AMT`
more cents"
else
if [ $COIN_VAR = "N" -o $COIN_VAR = "n" ];then                  #3rd IF
statement
 echo "$N_MESS,
         You have deposited $N_AMT cents. Please insert `expr 50 - $N_AMT`
more cents"
else
if [ $COIN_VAR = "R" -o $COIN_VAR = "r" ];then                   #4th IF
statement
 echo $R_MESS
else
 echo $U_MESS
fi
fi
fi
fi

done                                                                #END OF
WHILE LOOP
# END of concurrent IF-THEN statements and loop to ascertain which coin was
used





> > hey guys......thanks for the help.....
> > now i need to input a variable so that whether the user inputs upper or
> > lower case it will accept it
> > hence  this will work for "Q" but not for "q" ............. anyone wanna
> > help out .......... thanks again

> > read COIN_VAR
> > if [ $COIN_VAR = "Q" ];then                                         #1st
If
> > statement
> >   echo "$Q_MESS,
> >          You have deposited $Q_AMT cents. Please insert `expr 50 -
$Q_AMT`
> > more cents"
> > else

>        if [ "$COIN_VAR" = "Q" -o "$COIN_VAR" = "q"  ];then

>    or

>        case $COIN_VAR in
>           Q|q) echo "$Q_MESS, ...."
>                ;;
>           *) ;;   ## otherwise...
>        esac

> --
>     Chris F.A. Johnson                        http://cfaj.freeshell.org
>     ===================================================================
>     My code (if any) in this post is copyright 2002, Chris F.A. Johnson
>     and may be copied under the terms of the GNU General Public License

 
 
 

upper case vs lower case ****newbie*****

Post by Bit Twiste » Sun, 03 Nov 2002 11:23:57



> thanks guys..... i dont know the switches....hehehe
> right now i am trying to output to a variable --- my loop is below.... i am
> trying to have  the moaunt write to $MONEY.....
> i dont know what command to use hence when i type Q or R or D to represent
> money... i want to update money ...i dont know if you guys can see what i am
> trying to do....
> basically.... to buy a can of pop at 50cent --i have to iterate the loop ...
> arggghhhh i hate learning frmo scratch....
> but if you guys have any ideas to help-- it would be really aprpeciated :)

You are getting there. The human mind reduces the problem to it's
most complex form.

I do not see where you are setting the Q_AMT when you have
decided on which coin was supplied. Might want to check on
N_MESS and N_AMT

You might want to add the command

set -xv     enable debugging feature
    code to look at here
set -       disable debugging feature across code you want to look at.

Quote:> rishi

> # START of concurrent IF-THEN statements to ascertain which coin was used
> # Enter coin sequence, either Quarter (Q) , Dime (D) , Nickel (N) , or Coin
> Return (R)
> # This loop also contains IF-THEN statements that will tell you how much
> change you must put
> # Nested While Loop to repeat coin input

> while [ $MONEY -lt 50 ]                                             #Start
> of WHILE LOOP
> do

> echo " "
> echo "Please enter a coin (QDN) or request your change back (R) : "
> read COIN_VAR
> if [ $COIN_VAR = "Q" -o $COIN_VAR = "q"  ];then                 #1st If
> statement
>   echo "$Q_MESS,
>          You have deposited $Q_AMT cents. Please insert `expr 50 - $Q_AMT`
> more cents"
> else
> if [ $COIN_VAR = "D" -o $COIN_VAR = "d"  ];then                  #2nd IF
> statement
>  echo "$D_MESS,
>          You have deposited $D_AMT cents. Please insert `expr 50 - $D_AMT`
> more cents"
> else
> if [ $COIN_VAR = "N" -o $COIN_VAR = "n" ];then                  #3rd IF
> statement
>  echo "$N_MESS,
>          You have deposited $N_AMT cents. Please insert `expr 50 - $N_AMT`
> more cents"
> else
> if [ $COIN_VAR = "R" -o $COIN_VAR = "r" ];then                   #4th IF
> statement
>  echo $R_MESS
> else
>  echo $U_MESS
> fi
> fi
> fi
> fi

> done                                                                #END OF
> WHILE LOOP
> # END of concurrent IF-THEN statements and loop to ascertain which coin was
> used

 
 
 

upper case vs lower case ****newbie*****

Post by Chris F.A. Johnso » Sun, 03 Nov 2002 13:17:24







>> > hey guys......thanks for the help.....
>> > now i need to input a variable so that whether the user inputs upper or
>> > lower case it will accept it
>> > hence  this will work for "Q" but not for "q" ............. anyone wanna
>> > help out .......... thanks again

>> > read COIN_VAR
>> > if [ $COIN_VAR = "Q" ];then                                         #1st
> If
>> > statement
>> >   echo "$Q_MESS,
>> >          You have deposited $Q_AMT cents. Please insert `expr 50 -
> $Q_AMT`
>> > more cents"
>> > else

>>        if [ "$COIN_VAR" = "Q" -o "$COIN_VAR" = "q"  ];then

>>    or

>>        case $COIN_VAR in
>>           Q|q) echo "$Q_MESS, ...."
>>                ;;
>>           *) ;;   ## otherwise...
>>        esac

[please don't top post]

Quote:> thanks guys..... i dont know the switches....hehehe
> right now i am trying to output to a variable --- my loop is below.... i am
> trying to have  the moaunt write to $MONEY.....
> i dont know what command to use hence when i type Q or R or D to represent
> money... i want to update money ...i dont know if you guys can see what i am
> trying to do....
> basically.... to buy a can of pop at 50cent --i have to iterate the loop ...
> arggghhhh i hate learning frmo scratch....
> but if you guys have any ideas to help-- it would be really aprpeciated :)
> rishi

    If you initialize the variables MONEY, Q_AMT, D_AMT and N_AMT,
    your code runs without error, but doesn't do what you want.

    If you really want help, you should format your code more
    readably. I have replaced it with formatted code.

- Show quoted text -

Quote:>    while [ $MONEY -lt 50 ]  #Start of WHILE LOOP
>    do
>      echo " "
>      echo "Please enter a coin (QDN) or request your change back (R) : "
>      read COIN_VAR
>      if [ $COIN_VAR = "Q" -o $COIN_VAR = "q"  ];then
>          echo "$Q_MESS,
>             You have deposited $Q_AMT cents.
>             Please insert `expr 50 - $Q_AMT` more cents"
>      else
>          if [ $COIN_VAR = "D" -o $COIN_VAR = "d"  ];then
>              echo "$D_MESS,
>             You have deposited $D_AMT cents.
>             Please insert `expr 50 - $D_AMT` more cents"
>         else
>             if [ $COIN_VAR = "N" -o $COIN_VAR = "n" ];then
>                 echo "$N_MESS,
>                 You have deposited $N_AMT cents.
>                 Please insert `expr 50 - $N_AMT` more cents"
>             else
>                 if [ $COIN_VAR = "R" -o $COIN_VAR = "r" ];then
>                     echo $R_MESS
>                 else
>                     echo $U_MESS
>                 fi
>             fi
>         fi
>      fi
>    done

    The reason the script doesn't work is that you never store the
    balance after a payment is received.

    There are also ways you can make the code more efficient.

    First, you repeat the same code in 3 places; you only need it
    once.

    Second, you should use "elif" instead of "else if", or better
    still, use a case statement.

    Try this (it still needs some work):

       MONEY=0
       while [ $MONEY -lt 50 ]  #Start of WHILE LOOP
       do
         echo " "
         echo "Please enter a coin (QDN) or request your change back (R) : "
         read COIN_VAR
         if [ $COIN_VAR = "Q" -o $COIN_VAR = "q"  ];then
             AMT=25
         elif [ $COIN_VAR = "D" -o $COIN_VAR = "d"  ];then
             AMT=10
         elif [ $COIN_VAR = "N" -o $COIN_VAR = "n" ];then
             AMT=5
         elif [ $COIN_VAR = "R" -o $COIN_VAR = "r" ];then
             echo "Here, have your $MONEY cents back."
             break
         else
             echo "You have netered an invalid coin."
             continue
         fi

         MONEY=$(( $MONEY + $AMT ))    ## or MONEY=`expr $MONEY + $AMT`
         BALANCE=$(( 50 - $MONEY ))    ## or BALANCE=`expr 50 - $MONEY`

         echo " You have deposited $AMT cents.
                Please insert $BALANCE more cents"
       done

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

upper case vs lower case ****newbie*****

Post by Juergen Hec » Wed, 06 Nov 2002 23:25:13



> hey guys......thanks for the help.....
> now i need to input a variable so that whether the user inputs upper or
> lower case it will accept it
> hence  this will work for "Q" but not for "q" ............. anyone wanna
> help out .......... thanks again

> read COIN_VAR
> if [ $COIN_VAR = "Q" ];then                                         #1st If
> statement
>   echo "$Q_MESS,
>          You have deposited $Q_AMT cents. Please insert `expr 50 - $Q_AMT`
> more cents"
> else

In Posix-/Korn-Shells will work

read COIN_VAR
typeset -u COIN_VAR       ##### upper case
if [ "$COIN_VAR" = "Q" ];then  
...

Regards
Juergen

 
 
 

upper case vs lower case ****newbie*****

Post by Chris F.A. Johnso » Wed, 06 Nov 2002 23:58:00



> In Posix-/Korn-Shells will work

> read COIN_VAR
> typeset -u COIN_VAR       ##### upper case

    Not POSIX; ksh only.

Quote:> if [ "$COIN_VAR" = "Q" ];then  
> ...

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
 
 
 

upper case vs lower case ****newbie*****

Post by Dan Merc » Thu, 07 Nov 2002 00:28:33





>> In Posix-/Korn-Shells will work

>> read COIN_VAR
>> typeset -u COIN_VAR       ##### upper case

>     Not POSIX; ksh only.

some "POSIX" - those derived from ksh like HP-UX's.  It's not
a POSIX feature,  but some sh's support it.

--
Dan Mercer

If responding by email, include the phrase 'from usenet'
in the subject line to avoid spam filtering.

Quote:

>> if [ "$COIN_VAR" = "Q" ];then  
>> ...
> --
>     Chris F.A. Johnson                        http://cfaj.freeshell.org
>     ===================================================================
>     My code (if any) in this post is copyright 2002, Chris F.A. Johnson
>     and may be copied under the terms of the GNU General Public License

Opinions expressed herein are my own and may not represent those of my employer.
 
 
 

1. upper case vs lower case account names

My securty group, (Who haven't a clue how to spell unix), are trying
to force us to use mixed case account names on our Sun systems. This
goes against everything I've ever done in my past 12 years as a unix
sysadmin (Solaris, HP, AIX, SCO, Tru64).

Does anyone have any suggestions to support my case against it, other
than it's just the way things are done?

Garry

2. .netrc questions

3. Lower Case vs Upper Case - Apache Question

4. Connecting to NNTP server

5. lower case <-> upper case

6. Xfig on laptop; size problem??

7. Script to Convert Upper Case Filenames to Lower Case

8. Latest version

9. change lower case word to upper case using sed?

10. Convert upper case to lower case

11. Converting from lower case to upper case using sed

12. Help: how to convert lower case to upper case?

13. Upper case to lower case