|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|