Typeset command issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Typeset command issue
# 1  
Old 04-23-2013
Typeset command issue

Hi,
As per my understanding typeset wil lmake a variable constant or readonly and -i option will make a variable integer. But please see the below outputs
Code:
typeset -i abc=000001;echo $abc
1
typeset -i abc=0000010;echo $abc
8
typeset -i abc=00000100;echo $abc
64
typeset -i abc=000001000;echo $abc
512
typeset -i abc=0000010001;echo $abc
4096
typeset -i abc=0000010001;echo $abc
4097
typeset -i abc=0000010002;echo $abc
4098
typeset -i abc=0000010003;echo $abc
4099
typeset -i abc=0000010005;echo $abc
4101
typeset -i abc=00000016755;echo $abc
7661
typeset -i abc=16755;echo $abc
16755
uname -a
Linux uatXXXXXX6m7 xxxxxxxxx #1 SMP Wed Mar 28 01:54:56 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

Can any one please help me to explain why typset behaves like this
# 2  
Old 04-23-2013
The leading 0 indicates that it's an octal number.
# 3  
Old 04-23-2013
How can i avoid treating it as octal. Because i am storing the value to the varaiable from output of someother command like below
Code:
var=`grep "trailor" sample|cut -c20-25`
typeset -i abc=$var

# 4  
Old 04-23-2013
Code:
$ x=0000008
$ echo $x
0000008
$ y=`echo $x | sed "s/^0*//"`
$ echo $y
8

Code:
var=`grep "trailor" sample|cut -c20-25`
int_var=`echo $var | sed "s/^0*//"`
typeset -i abc=$int_var

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Typeset issue

function fxn { echo "target in build_ndm is $target" } function main { target=${server_type} echo "target in main is $target" fxn } In the above the value of target is not being propagated to the function while ideally it should be since typeset variables are visible in sub... (2 Replies)
Discussion started by: sharad.40216
2 Replies

2. Linux

Issue with typeset in Linux

Hi All, typeset -Z4 curtime command is giving different result than expected inside scripts in linux.But it gives expected results outside the scripts.Can you please help us ---------- Post updated at 05:37 AM ---------- Previous update was at 05:25 AM ---------- curTime=`date +%H%M`... (5 Replies)
Discussion started by: sumqwe
5 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. Shell Programming and Scripting

Struck with Typeset Command

Can someone explain whats this below command will do exactly.. typeset tmpFile1 tmpDir1 rc fileName fullName bc typeset tmpFile1 tmpFile2 rc fileSuffix uef typeset origFile bc fullName tmpDir1 remoteCmd inFile newInFile typeset num fn curDate fileSuffix ucFileName Since i'm new to... (1 Reply)
Discussion started by: help_scr_seeker
1 Replies

5. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

6. Shell Programming and Scripting

Error while using typeset command

I am having a problem with typeset command: It is behaving differently in different machines. Machine 1: /marc_data/marc_project/owb_marc_adaptor/owb_marc_adaptor_load/bin>echo $0 -bash /marc_data/marc_project/owb_marc_adaptor/owb_marc_adaptor_load/bin>vi fn2.ksh... (6 Replies)
Discussion started by: boopathyvasagam
6 Replies

7. UNIX and Linux Applications

typeset-r

Hi All , Can any one help me the meaning of typeset -r Thanks, venkat (1 Reply)
Discussion started by: venkatakotiy
1 Replies

8. Shell Programming and Scripting

typeset

Can anyone show me a simple practical usage of typeset. (1 Reply)
Discussion started by: balaji_prk
1 Replies

9. UNIX for Dummies Questions & Answers

typeset and export command difference

Can anyone please explain what the difference is between these two commands typeset - ? export - i know with this even child process can read the variable Declare - ? i use bash shell http://cnswww.cns.cwru.edu/~chet/bash/bashref.html#SEC58 states that " The typeset command is... (0 Replies)
Discussion started by: systemsb
0 Replies

10. UNIX for Dummies Questions & Answers

TYPESET use

Hi all, I have problem understanding shell script.Written that $bindir/put_load.ksh ; typeset RV= $? I dont have any other document about script. How can i find that $bindir is exist or not what is the content of that, i am working on new box . how can i search that in old box what... (4 Replies)
Discussion started by: sam71
4 Replies
Login or Register to Ask a Question