|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi All
Can expr handle decimal point cnt_idle=23 #expr $cnt_idle / 8.0 expr: 0402-046 A specified operator requires numeric parameters. #expr $cnt_idle / 8 2 moonhk |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Sep 5, 12:14 pm, moonhk <moon_ils...@yahoo.com.hk> wrote:
> Hi All > Can expr handle decimal point > > cnt_idle=23 > #expr $cnt_idle / 8.0 > expr: 0402-046 A specified operator requires numeric parameters. > > #expr $cnt_idle / 8 > 2 > > moonhk This depends on your version of shell in ksh93 for example, you can declare a floating point variable: set -F var_name |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
moonhk wrote:
> Hi All > Can expr handle decimal point > > cnt_idle=23 > #expr $cnt_idle / 8.0 > expr: 0402-046 A specified operator requires numeric parameters. > > #expr $cnt_idle / 8 > 2 > > moonhk > expr won't work with float try like this : echo "scale=2;$cnt_idle / 8" | bc -l Regards, Thobias Vakayil |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Wed, 05 Sep 2007 09:40:52 -0000, hyperboogie
<hyperboogie@gmail.com> wrote: > > > On Sep 5, 12:14 pm, moonhk <moon_ils...@yahoo.com.hk> wrote: >> Hi All >> Can expr handle decimal point >> >> cnt_idle=23 >> #expr $cnt_idle / 8.0 >> expr: 0402-046 A specified operator requires numeric parameters. >> >> #expr $cnt_idle / 8 >> 2 >> >> moonhk > > This depends on your version of shell > in ksh93 for example, you can declare a floating point variable: > set -F var_name > If the shell allows floating point, it may be allowed only in $(( )) or let var=expression. -- lisp, v.: To call a spade a thpade. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 2007-09-05, hyperboogie wrote:
> On Sep 5, 12:14 pm, moonhk <moon_ils...@yahoo.com.hk> wrote: >> Hi All >> Can expr handle decimal point >> >> cnt_idle=23 >> #expr $cnt_idle / 8.0 >> expr: 0402-046 A specified operator requires numeric parameters. >> >> #expr $cnt_idle / 8 >> 2 >> >> moonhk > > This depends on your version of shell No, expr doesn't know about floating point numbers, regardless of shell. > in ksh93 for example, you can declare a floating point variable: > set -F var_name Any shell can have a floating point variable, but most shells cannot perform arithmetic operations on it. -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
2007-09-5, 11:00(-04), Chris F.A. Johnson:
[...] >> in ksh93 for example, you can declare a floating point variable: >> set -F var_name > > Any shell can have a floating point variable, but most shells > cannot perform arithmetic operations on it. [...] shells are tools to call other tools. So all shells can do floating point arithmetic, they just need to call utilities that do floating point arithmetics such as bc or awk. If you mean internally, then you just need to find a shell that has bc or awk built in, but why would you care if they are builtin or not? zsh and ksh93 have special constructs to do floating point arithmetics without calling a command. -- Stéphane |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 9 6 , 5 27 , Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-09-5, 11:00(-04), Chris F.A. Johnson: > [...]>> in ksh93 for example, you can declare a floating point variable: > >> set -F var_name > > > Any shell can have a floating point variable, but most shells > > cannot perform arithmetic operations on it. > > [...] > > shells are tools to call other tools. So all shells can do > floating point arithmetic, they just need to call utilities that > do floating point arithmetics such as bc or awk. > > If you mean internally, then you just need to find a shell that > has bc or awk built in, but why would you care if they are > builtin or not? > > zsh and ksh93 have special constructs to do floating point > arithmetics without calling a command. > > -- > Stéphane Hi All Thank. I will using bc for decimal calculation. moonhk |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On 9 6 , 5 27 , Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-09-5, 11:00(-04), Chris F.A. Johnson: > [...]>> in ksh93 for example, you can declare a floating point variable: > >> set -F var_name > > > Any shell can have a floating point variable, but most shells > > cannot perform arithmetic operations on it. > > [...] > > shells are tools to call other tools. So all shells can do > floating point arithmetic, they just need to call utilities that > do floating point arithmetics such as bc or awk. > > If you mean internally, then you just need to find a shell that > has bc or awk built in, but why would you care if they are > builtin or not? > > zsh and ksh93 have special constructs to do floating point > arithmetics without calling a command. > > -- > Stéphane Hi All Thank. I will using bc for decimal calculation. moonhk |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On 2007-09-05, Stephane CHAZELAS wrote:
> 2007-09-5, 11:00(-04), Chris F.A. Johnson: > [...] >>> in ksh93 for example, you can declare a floating point variable: >>> set -F var_name >> >> Any shell can have a floating point variable, but most shells >> cannot perform arithmetic operations on it. > [...] > > shells are tools to call other tools. The shell is also a full programming language, and complex programs can be written in a POSIX shell without using external commands, which make a script considerably slower. Even more can be done with a shell that has other extensions (arrays, more parameter expansions, etc.), such as bash and ksh93. -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
![]() |
| Outils de la discussion | |
|
|