![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Rounding Script Help
I need some help with my rouding script. I have started pretty much from scratch and have no idea if its correct or even close but I have been trying and have gotten to this point. i keep getting syntax errors and im not sure what is wrong. Here is what I got Code:
let value=$1; while [ magn=1;"$value">\(magn*10\); magn*=10 ] do let digit=( $value/magn )%10 if [ $digit >= 5 ] then $value+=( "10"-$digit )*$magn else $value-=( $digit*$magn ) fi done echo $value its supposed to take ./rounders 1447 and output 2000 I posted this in the OS sub forum also. NOOB mistake i know but hey its my first day. SOrry |
|
|||
|
Your script seems to have a considerable disregard for syntax. I suggest you start with some minimal segments of your code and just see if they work. ---------- Post updated at 02:17 ---------- Previous update was at 02:02 ---------- Alright, here you go. I turned it further into a bash/ksh kind of script: Code:
value=$1
for (( magn=1;value>magn*10; magn*=10 ))
do
(( digit=(value/magn)%10 ))
if (( digit >= 5 ))
then
(( value+=(10-digit)*magn ))
else
(( value-=(digit*magn) ))
fi
done
echo $value
It doesn't work right, but at least it runs
|
|
|||
|
Quote:
variables cannot contain spaces, and neither should file names. unix not windows... actually most languages do not allow this, c/c++ java, to name a few. |
|
|||
|
Not sure I follow. I dont think i put any spaces in either. Is there something I missed?
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Rounding Script Help | kingrj46 | Linux | 0 | 11-26-2009 03:33 PM |
| Rounding numbers down | dcfargo | UNIX for Dummies Questions & Answers | 5 | 09-16-2008 08:14 PM |
| Rounding off to the next whole number | damansingh | Shell Programming and Scripting | 2 | 07-17-2008 07:18 AM |
| Rounding problem | shash | UNIX for Dummies Questions & Answers | 2 | 01-18-2007 05:33 AM |
| Rounding off using BC. | noodlesoup | Shell Programming and Scripting | 3 | 09-11-2006 01:38 AM |