Re: newbie question: how to convert str to int in c-shell?
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Tue, 31 Oct 2006 08:30:50 +0000
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
.
- References:
- newbie question: how to convert str to int in c-shell?
- From: neo
- Re: newbie question: how to convert str to int in c-shell?
- From: Chris F.A. Johnson
- newbie question: how to convert str to int in c-shell?
- Prev by Date: Re: newbie question: how to convert str to int in c-shell?
- Next by Date: Re: newbie question: how to convert str to int in c-shell?
- Previous by thread: Re: newbie question: how to convert str to int in c-shell?
- Next by thread: Re: newbie question: how to convert str to int in c-shell?
- Index(es):
Relevant Pages
|