You are not logged in.

#1 2009-01-19 22:44:06

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 681
Website

bash loops, why can't I get them right. HELP

function addproduct {
x="n"
while $x == [n]
do
    clear
    echo Add new product
    echo ""
    echo "Product number:"
    read PRID
    echo "Product description:"
    read PRDE
    echo "Product type:"
    read PRTY
    echo "Product manufacturer:"
    read PRMF
    echo "Product price:"
    read PRPR

    #PREY=`date +%y`
    #PREY=$(( $PREY * 12 ))
    #PREM=`date +%m`
    #PRED=$(( $PREY + $PREM ))

    clear
    PRODUCT="$PRID | $PRDE | $PRTY | $PRMF | $PRED | £$PRPR"
    echo $PRODUCT
    echo "are details correct?"
    read x
done
echo $PRODUCT >> prices.dat

}

The loop continues forever, I need it to stop on a y.

also why I am here

Can I get the read to follow onto the end of my echo line instead of underneath it?

You can probably work out what I am trying to do with the date part that is temp #'d out.  Any idea why that does not work?

Many Thanks

Last edited by gazj (2009-01-19 22:44:54)

Offline

#2 2009-01-19 22:52:50

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: bash loops, why can't I get them right. HELP

I think this is something like what you're after...

x="n"
while [ $x == "n" ] ; do
    clear
    echo Add new product
    echo ""
    read -p "Product number:" PRID
    read -p "Product description:" PRDE
    read -p "Product type:" PRTY
    read -p "Product manufacturer:" PRMF
    read -p "Product price:" PRPR

    clear
    PRODUCT="$PRID | $PRDE | $PRTY | $PRMF | $PRED | £$PRPR"
    echo $PRODUCT
    echo "are details correct?"
    read x
done
echo $PRODUCT >> prices.dat

Last edited by fukawi2 (2009-01-19 22:53:27)

Offline

#3 2009-01-19 22:56:17

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 681
Website

Re: bash loops, why can't I get them right. HELP

Thank you so so much, was starting to lose my rag smile

I should have worked out the read bit, is nearly the same as old c64 basic

ie

input "Question";a$

Silly me

Last edited by gazj (2009-01-19 22:59:13)

Offline

Board footer

Powered by FluxBB