Computing.Net > Forums > Unix > Script that aks for input

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Script that aks for input

Reply to Message Icon

Original Message
Name: UnixNewbie
Date: April 16, 2004 at 08:35:38 Pacific
Subject: Script that aks for input
OS: Win ME
CPU/Ram: 950 Mhz
Comment:

Can anybody help me get started with this?
I need to write a script that asks the user for integer values, one at a time. Add up the integers and prints the current total, before prompting for thenext integer. This script will work until "x" is detected. Once the "x" is detected print the final total and quit.
Any help is highly appreciated.
Thanks

UnixNewbie


Report Offensive Message For Removal


Response Number 1
Name: WilliamRobertson
Date: April 16, 2004 at 14:46:10 Pacific
Reply: (edit)

In ksh,

read varname?"prompt message: "

populates $varname with user input.


Report Offensive Follow Up For Removal

Response Number 2
Name: Wolfbone
Date: April 19, 2004 at 09:38:12 Pacific
Reply: (edit)

One-liner for bash:

sum=0 ; until [[ $var = x ]] ; do echo -e "Total so far: $sum\nType an integer or 'x' to end" ; read var ; ((sum+=$var)) ;done ; echo "Final total: $sum" ; unset var sum

Probably needs recent bash version.


Report Offensive Follow Up For Removal

Response Number 3
Name: quynh
Date: May 11, 2004 at 13:23:13 Pacific
Reply: (edit)

what about cshell? how do i ask for input? echo '??


Report Offensive Follow Up For Removal

Response Number 4
Name: WilliamRobertson
Date: May 12, 2004 at 14:57:09 Pacific
Reply: (edit)

I couldn't see anything about prompting for input in the man pages, so unless I'm missing something add another limitation to the list.

Why would you want to use csh?


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software