The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 03:18 PM
Sed a variable which has - character in it potro Shell Programming and Scripting 6 03-14-2008 05:24 AM
hw can i count the number of character in a file by perl trupti_rinku Shell Programming and Scripting 1 10-31-2006 07:27 AM
Sed character number specification mvalonso UNIX for Dummies Questions & Answers 4 05-10-2006 10:32 AM
Number or Character j1yant Shell Programming and Scripting 3 02-10-2003 02:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-26-2005
noobian noobian is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 1
defining a variable as a number or character?

I am writing a script that needs to accept numbers into a variable by prompting and using the code
read num
case $num in
000)
break
;;
*)

I am fairly new to unix and am loving the versatility of the language but need a little shove in the right direction. I know how to define variables in C++, but how do you make sure that a variable is a number? And if a character string is entered instead of a number is there any way that i could send an error message and start the loop again.
thank you in advance
  #2 (permalink)  
Old 04-26-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:

#!/bin/ksh
# define num as integer and set to zero
typeset -i num=0
num is now an integer variable. Works in the Korn shell.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0