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
.



Relevant Pages

  • Feedback on scripting design
    ... At the start of the game, a startup script is called, which is responsible for setting up all the initial game values, selecting the starting map, and any other miscellaneous things you want taken care of at the beginning of the game. ... Interface_NewMap(int Width, int Height); ... Interface_Hurt(int MonsterID, int Damage, int DamageTypeFlags); ...
    (rec.games.roguelike.development)
  • Scheduler fairness problem on 2.6 series (Attn: Nick Piggin and others)
    ... latest kernel, so I tried 2.6.7 but it shows the same signs. ... I managed to create a test program to reproduce it. ... I run in one shell a script to check for slowdowns: ... int iterations = 0; ...
    (Linux-Kernel)
  • Re: MySQL to SQL
    ... BIOS_RELEASE_DATE datetime default NULL, ... NUM_PROCESSORS int NOT NULL default '0', ... Copyright 1985-2001 Microsoft Corp. ... Microsoft Windows Script Host Version 5.6 ...
    (microsoft.public.scripting.wsh)
  • Ruby Versions and other languages performane comparison
    ... I ran this simple ruby script ... perl, python and C. ... int max = 5000; ...
    (comp.lang.ruby)
  • Re: MySQL to SQL
    ... How does this VBScript recognize the ... MySQL.sql script to do the compare? ... bigint without the size spec following them? ... to just int. ...
    (microsoft.public.scripting.wsh)