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 > newbie question: how to convert str to int in c-shell?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

newbie question: how to convert str to int in c-shell?

Réponse
 
LinkBack Outils de la discussion
Vieux 31/10/2006, 05h29   #1
neo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut newbie question: how to convert str to int in c-shell?

hi, i am a newbie in shell. i am using c shell.
say convert a argument to int.
if it is not a int , some flag or message should be got.
how to do so in a neat way?
thanks.

  Réponse avec citation
Vieux 31/10/2006, 08h07   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: how to convert str to int in c-shell?

On 2006-10-31, neo wrote:
> hi, i am a newbie in shell. i am using c shell.


If you want to write a script, don't use csh.

> say convert a argument to int.
> if it is not a int , some flag or message should be got.
> how to do so in a neat way?


A simple test for a numeric argument, in a standard shell is:

case $n in
*[!0-9]*) printf "%s\n" "Not a number" ;;
esac


--
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 31/10/2006, 08h30   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: how to convert str to int in c-shell?

2006-10-31, 03:07(-05), Chris F.A. Johnson:
> On 2006-10-31, neo wrote:
>> hi, i am a newbie in shell. i am using c shell.

>
> If you want to write a script, don't use csh.
>
>> say convert a argument to int.
>> if it is not a int , some flag or message should be got.
>> how to do so in a neat way?

>
> A simple test for a numeric argument, in a standard shell is:
>
> case $n in
> *[!0-9]*) printf "%s\n" "Not a number" ;;


"" | *[!0-9]*) ...

for unsigned int, assuming you don't want to check for
boundaries (too big numbers) and that 089 would not be taken as
an invalid octal number.

> esac




--
Stéphane
  Réponse avec citation
Vieux 31/10/2006, 11h27   #4
neo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: how to convert str to int in c-shell?


Chris F.A. Johnson ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:

> On 2006-10-31, neo wrote:
> > hi, i am a newbie in shell. i am using c shell.

>
> If you want to write a script, don't use csh.

why?
if i can chose, i'd use python. yes, ...maybe i can chose.

>
> > say convert a argument to int.
> > if it is not a int , some flag or message should be got.
> > how to do so in a neat way?

>
> A simple test for a numeric argument, in a standard shell is:
>
> case $n in
> *[!0-9]*) printf "%s\n" "Not a number" ;;
> esac
>

it works, thanks.

>
> --
> 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 31/10/2006, 12h50   #5
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: how to convert str to int in c-shell?

neo wrote:
> Chris F.A. Johnson ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:
>
>
>>On 2006-10-31, neo wrote:
>>
>>>hi, i am a newbie in shell. i am using c shell.

>>
>> If you want to write a script, don't use csh.

>
> why?


See question 17 in the FAQ
(http://home.comcast.net/~j.p.h/cus-faq-2.html#17).

Ed.
  Réponse avec citation
Vieux 31/10/2006, 20h06   #6
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: how to convert str to int in c-shell?

On 2006-10-31, neo wrote:
>
> Chris F.A. Johnson ??????:
>
>> On 2006-10-31, neo wrote:
>> > hi, i am a newbie in shell. i am using c shell.

>>
>> If you want to write a script, don't use csh.

> why?


See these articles:

<http://www.grymoire.com/Unix/CshTop10.txt>
<http://www.grymoire.com/Unix/Csh.html#uh-0>
<http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>


--
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 07h00.


É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,10112 seconds with 14 queries