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
.



Relevant Pages

  • reading userAccountControl flags
    ... I'm trying to determine if an AD user has the "Password never expires" flag ... I've only been able to find some vb script examples that show how to do ... type 'object' and 'int' ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with Exit Status
    ... I am trying a script with the following logic in bash: ... in the first line you included spaces flanking the '=' character. ... Awk will happily accept ''. ... Shell Scripting Recipes: | My code in this post, if any, ...
    (comp.unix.shell)
  • Re: sed , empty the file
    ... If i put an echo before sed and run it many times, ... empty the file, why? ... the script ... Shell Scripting Recipes: | My code in this post, if any, ...
    (comp.os.linux.misc)
  • Re: combining the result of processing various commands and setting it in a variable
    ... > see any references to the ncurses library there and I need to keep ... > script querying the kernel ring buffers. ... > scripts back to your ncurses code? ... Shell Scripting Recipes: | My code in this post, if any, ...
    (comp.unix.shell)
  • Re: What is the name for
    ... I have a script v which edits any file in the current directory ... than the equivalent sed or awk script. ... Shell Scripting Recipes: | My code in this post, if any, ...
    (comp.unix.shell)