why doesnt my script work!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting why doesnt my script work!!!
# 1  
Old 02-17-2004
number and its decimal

Is there a utility or command I can use to tell the number of decimal places a number has. For instance, if the number is 432, it will give hundred as the number of decimal places.
# 2  
Old 02-17-2004
Re: number and its decimal

Quote:
Originally posted by Heedunk
... if the number is 432, it will give hundred as the number of decimal places.
Heedunk, I'm not sure I follow.. in math, there is no "number of decimal places", unless you're talking about two numbers after the decimal, or three numbers before the decimal. I assume you want to display what the largest column is..? As in ten, hundred, or a thousand?

Maybe someone has a better solution, but I think you'll need a case statement... in ksh:
Code:
a=432.27
b=${a%%.*}
case ${#b} in
  2) echo "tens" ;;
  3) echo "hundreds" ;;
esac

Returns:
> hundreds

# 3  
Old 02-17-2004
as far as i know there is no utility that displays the mathamatical notation of one, tens, hundreads, thousands....... or its reverse.

thats not to say that there are none. because i am sure there are but by default for a standard OS install there are none. (that i am aware of).

you can easily come up with a script to do it tho. all you would have to do is:

1) validate the string is only numeric.
2) split the string on a decimal.
3) count the number of char. the pre decimal sting is.
4) have some sort fo loop or case statement so for x charicters it is a hundread or a thousand or a billion and so one.


or do something like posted above.
# 4  
Old 02-17-2004
Heedunk, looking at your questions thus far, either you're learning unix on your own and are new at it or you're posting homework assignments. If it's the former, then welcome to the world of unix!

If it's the latter, then the code I put will probably be too advanced to turn into a teacher anyway... follow Norsk's logic to come up with a way.
# 5  
Old 02-17-2004
Because this may be homework, I won't explain this. Note though that in the construct "l(432)", the first character is a letter "l".

echo "a = l(432) / l(10) ; scale=0 ; a = a / 1 ; 10^a" | bc -l
# 6  
Old 02-20-2004
why doesnt my script work!!!

I get an expr syntax error. here is my code


#!/bin/sh
echo 'Enter a number: \c'
read number

echo $number > test #copy value in number to file test

decimal=`wc -m test` #read decimal places for test

answer=`expr $decimal - 1` #remove new line character

case $answer in
1)
echo One
;;
2)
echo Ten
;;
3)
echo Hundred
;;
4)
echo Thousand
;;
5)
echo Ten Hundred
;;
6)
echo Million
;;
7)
echo Ten Million
;;
8)
echo Hunderd Million
;;
*)
error: value exceeds limitations of program
;;
esac
# 7  
Old 02-20-2004
I'd merge them if I could. (Consider it done)

Between these two lines:
decimal=`wc -m test` #read decimal places for test
answer=`expr $decimal - 1` #remove new line character

place:
echo "$decimal"

to see what's really in that variable. I suspect more than you think...

But what I'd really like to know is why you didn't even seem to try the suggestions from the previous post? Was Perderabo correct in his assumption?

------
Thanks, RTM. Smilie

Actually, you should just post the exact error you see on screen .. something more than "i got a syntax error".

Last edited by oombera; 02-20-2004 at 10:22 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[SOLVED] Mv command doesnt work in shell script

Hi All, i created the below script to move file with xml extension from one directory to another,but the mv command is not working inside the shell script, #!/us/bin/ksh filepath="/apps/extract" filename="*.xml" foldername=2191POB000_$(date +%Y%m%d%H%M%S) mkdir -p "$filepath/$foldername"... (3 Replies)
Discussion started by: Radhas
3 Replies

2. UNIX for Dummies Questions & Answers

why doesnt it work?

I am trying to print out two fields in a file using awk. So, I have got awk -F '\t' 'NF = 2 {print $1 $2 "]"}' two.txt in a script called what.awk When i run this version like this - ./what.awk then it runs however I want to run the program like this awk -f what.awk two.txt. When I... (8 Replies)
Discussion started by: The undertaker
8 Replies

3. AIX

Vi doesnt work

Hi Guys, I have a strange problem.( AIX 6.1) "vi" is not working at all..Whenever i #vi <anythin> ,, it returns the prompt back. Any clues folks?? (14 Replies)
Discussion started by: muzahed
14 Replies

4. Shell Programming and Scripting

compiler doesnt work

this is my file I have written. // My first C++ program #include <iostream> int main() { std::cout << "Hi there!" << std::endl"; std::cout << "This is my first C++ program" << std::endl"; return(0); } This is the error I get, why? $ g++ first.cpp ksh: g++: not found (1 Reply)
Discussion started by: gustave
1 Replies

5. Shell Programming and Scripting

loop doesnt work

It just does the break...even though the files are not the same... # Compare extracts #========================================== count=0 while (( count < 5 )) do (( count+=1 )) echo "Try $count" file1=$(ls -l /tmp/psjava.xml|... (5 Replies)
Discussion started by: sigh2010
5 Replies

6. Shell Programming and Scripting

A script doesnt work properly when crontab

Hi, I have a script which does a tar and sends it to another server as backup. Script is as below # Locations to be backed up. Seperate by space BACKUP_LOCATIONS=/repos/subversion BACKUP_BASE_FOLDER=/bakpool BACKUP_FILE_NAME_ROOT=svn-backup START_TIME_DISP=`date` START_TIME=`date... (11 Replies)
Discussion started by: digitalrg
11 Replies

7. Red Hat

ldapsearch doesnt work.

Hii All, I am using openldap v2.3 on redhat El-4. When i run ldapsearch it returns all the entries. The command runs successfully. But when I run the ldapsearch with following filter option it doesnt work and immediately returns to the shell. ldapsearch uidNumber>=2000 I've started slapd... (0 Replies)
Discussion started by: shamik
0 Replies

8. UNIX for Dummies Questions & Answers

cp doesnt work - Help

When trying to copy a file in Solaris 8 it doesnt copy file or give a error. This worked 100% until the 29th. I've checked the rights and everything seems fine: drwxrwxrwx 2 bmuser bmgroup 11776 Jan 3 10:32 spool This is the file I want to copy: -rwxrwxrwx 1 bmuser bmgroup ... (26 Replies)
Discussion started by: rudi.okelly
26 Replies

9. HP-UX

ls command doesnt work

Good Day I mistakely renamed the dld.sl file in the /usr/lib directory. When i try to ls/ftp into the box i get this error :eek: crt0: ERROR couldn't open /usr/lib/dld.sl errno:000000002 I have tried to rename it back from the renamed file to the original file name, but it gives me the... (2 Replies)
Discussion started by: shawnbishop
2 Replies

10. UNIX for Dummies Questions & Answers

cd.. doesnt work

hi when i want to go to previous directory by typing cd.. i get the following message $ cd.. ksh: cd..: not found Please help rintingtong (2 Replies)
Discussion started by: rintingtong
2 Replies
Login or Register to Ask a Question