PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Can expr handle decimal point
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Can expr handle decimal point

Réponse
 
LinkBack Outils de la discussion
Vieux 05/09/2007, 10h14   #1
moonhk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Can expr handle decimal point

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

  Réponse avec citation
Vieux 05/09/2007, 10h40   #2
hyperboogie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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

  Réponse avec citation
Vieux 05/09/2007, 11h06   #3
Vakayil Thobias
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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
  Réponse avec citation
Vieux 05/09/2007, 14h05   #4
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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.
  Réponse avec citation
Vieux 05/09/2007, 16h00   #5
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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
  Réponse avec citation
Vieux 05/09/2007, 22h27   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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
  Réponse avec citation
Vieux 06/09/2007, 01h47   #7
moonhk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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

  Réponse avec citation
Vieux 06/09/2007, 01h47   #8
moonhk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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

  Réponse avec citation
Vieux 06/09/2007, 02h01   #9
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can expr handle decimal point

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16000 seconds with 17 queries