| 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
|
Original Message
|
Name: UnixNewbie
Date: April 16, 2004 at 08:35:38 Pacific
Subject: Script that aks for inputOS: Win MECPU/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 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
|

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