Shell script : value under 1 (0,0...) is accepted as 0?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script : value under 1 (0,0...) is accepted as 0?
# 1  
Old 01-31-2012
Shell script : value under 1 (0,0...) is accepted as 0?

Hi all,,

I have this script
Code:
ctr=$(( 1/1000 ))
while [ 1 ]
do
  echo $ctr >> test.txt
done

However, it puts 0 instead of 0.001

How can I put 0.001 in the text file?

Thank you

Last edited by Scott; 01-31-2012 at 06:08 AM.. Reason: Code tags
# 2  
Old 01-31-2012
Could this help you ?
Code:
 ctr=$(awk 'BEGIN{print (1/1000)}')

OR
Code:
 ctr=$(echo 'scale=3;1/1000' | bc)

# 3  
Old 01-31-2012
If you can use ksh93 or a shell that supports declaring variables as floats:
Code:
$ cat efs
#!/usr/dt/bin/dtksh

typeset -F a=1
typeset -F b=1000

ctr=$(( ${a}/${b} ))

print $ctr
$ efs
0.001
$

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Cybersecurity

Certificates accepted/rejected depending on what service I use...

Hey everyone. I was at my local star bucks, which has open free wifi. And I (against my better judgement) deceided to check my school email. I was using their wifi network. when I went to go login, I was presented with the safari prompt "Can not Verify Server identity". I clicked 'details' and... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

2. Shell Programming and Scripting

BASH weird acting: unquoted parameter accepted as quoted one !

In one session I have strange behavior of the bash-shell: SDX-Q> echo ">$ss<" #this is just to present the $ss var: > lll kkk < SDX-Q> # more obviose: SDX-Q> od -cb <<<"$ss" 0000000 l l l k k k \n 040 040 040 154 154 154 040... (3 Replies)
Discussion started by: alex_5161
3 Replies

3. Shell Programming and Scripting

Quick edit on accepted variable.

I am new newbie to unix. I am taking user input using ksh script. The valid value user can enter is a) Numeric 1 to 500 b) character e, r c) e1 to e100 I figured out how to deal with a) and b) but want to separate characters when user enter e1 to e100 I want to store e in... (1 Reply)
Discussion started by: ekb
1 Replies

4. Solaris

Password accepted but kicked out

The Sun Solaris x86 system seemed to accept my username and password when I do SSH, but then the login prompt went away or hang. What happened? (8 Replies)
Discussion started by: conandor
8 Replies

5. Forum Support Area for Unregistered Users & Account Problems

Password reset not being accepted

Why would a password reset, a provided numerical value thru email, not be accepted when trying to log in with it? I have expired the 5 login attempts twice with still no acceptance. thanks for the help (3 Replies)
Discussion started by: W.A.C.
3 Replies

6. Post Here to Contact Site Administrators and Moderators

Solution accepted

Is there any status like open/close or solution is accepted by the owner? This can make a lot of difference as we need not look for questions that have already been answered.(saves time). (1 Reply)
Discussion started by: sudhamacs
1 Replies

7. UNIX for Dummies Questions & Answers

Can you force local NTP server to be accepted as "suitable"?

Is there some way to force the NTP server on a brand-new install to be "suitable" to sync other servers from? (I'm more concerned with synchronization between machines, and less concerned with what the actual time they sync to is) For example, whenever I install fresh from the Fedora DVDs and... (0 Replies)
Discussion started by: jjinno
0 Replies

8. Solaris

MAILTO Not Accepted In Crontab

I have 3 solaris 9 servers 1 allows me to use MAILTO in the crontab, but the other 2 dont. Error MAILTO=oracle crontab: error on previous line; unexpected character found in line. crontab: errors detected in input, no crontab file generated. Any Ideas?? (8 Replies)
Discussion started by: raza
8 Replies

9. UNIX for Dummies Questions & Answers

mac 10.4>terminal>linux remote server>ssh login accepted>session closed-why?

mac 10.4>terminal>linux remote server>ssh login accepted>session closed-why? AHHHH!! I have been connecting to the server with the line: ssh userid@website.com The remote server accepts my password; logs me in with ssh; posts a lovely welcome message AND closes the session. Is this a "term... (0 Replies)
Discussion started by: xprankard
0 Replies
Login or Register to Ask a Question