Is type casting possible in scripts

Is type casting possible in scripts

Post by caroli » Wed, 25 Jul 2001 19:17:21



Hi,
  Can I type cast a variable used in scripts, if so how.
  Thanks in advance.
caroline.c
 
 
 

Is type casting possible in scripts

Post by Ari Makel » Wed, 25 Jul 2001 21:11:33



>   Can I type cast a variable used in scripts, if so how.

Shell scripts have no types so you have nothing to cast i.e. you can
handle the same variable both as a number or as a string.

--

#                                                 http://arska.org/hauva/ #

print "Navigare necesse est, vivere non est necesse - Pompeius\n";

 
 
 

Is type casting possible in scripts

Post by Dave Grantie » Wed, 25 Jul 2001 20:50:42


You can do a 'little' type casting, although I suspect it may not be
what you have in mind.
Check out man ksh and look for typeset.


> Hi,
>   Can I type cast a variable used in scripts, if so how.
>   Thanks in advance.
> caroline.c

--
+---------------------+---------------+


+---------------------+---------------+
 
 
 

Is type casting possible in scripts

Post by Dan Merc » Wed, 25 Jul 2001 21:51:32





>>   Can I type cast a variable used in scripts, if so how.

> Shell scripts have no types so you have nothing to cast i.e. you can
> handle the same variable both as a number or as a string.

Not true for ksh:

     $ typeset -i10 x=0
     $ unset y
     $ y=0
     $ x=x+1
     $ y=y+1
     $ print "x=$x y=$y"
     x=1 y=y+1

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

Is type casting possible in scripts

Post by Matthieu PARISO » Thu, 26 Jul 2001 00:49:04


In bash, you can declare a variable as an integer bashing :
declare -i myvariable
This will force arithmetic evaluation whe the variable is assigned (like 'let' or $(( ..)) expressions)

> Hi,
>   Can I type cast a variable used in scripts, if so how.
>   Thanks in advance.
> caroline.c