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`
typeset -Z4 fmtCurTime=$curTime
echo $fmtCurTime

What symptoms do you have? I have pasted your code into AIX and RedHat Linux without issue, but then I have my shell set as ksh. Doing it in bash gives me the following:-

bash: typeset: -Z: invalid option
typeset: usage: typeset [-aAfFilrtux] [-p] name[=value] ...

Is this your problem? You don't say, so it's a bit difficult to help. :rolleyes:

Robin
Liverpool/Blackburn
UK

Hi,

We are in Red Hat Linux and ksh.

So, just to be clear,

Hi,

Please try below code in AIX and Red Hat Linux...you will see different results

typeset -i currentTime=0
currentTime=`date +%H%M`
echo $currentTime

The same output for me. What do you see? What shell are you using on the two servers? Can you paste the output from:-

ps -f
typeset -Z4 currentTime=`date +%H%M`
echo $currentTime

I've changed the typeset to set a 4 character field padded with leading zeros, because I was running this at 09:25 local time to me, so the output I got was just 925 . On both AIX and RHEL, I am using ksh, but if I swap to bash (the default for RHEL) then I get the following output using typeset -i :-

bash: 0928: value too great for base (error token is "0928")

The -Z flag for typeset is not valid for bash. I've not needed it yet, but it would be good to know of a way to acheive the same effect. :confused: When forcing it in, I get:-

typeset -Z4 my_var
bash: typeset: -Z: invalid option
typeset: usage: typeset [-aAfFilrtux] [-p] name[=value] ...

:rolleyes:

Can you paste what you are seeing please, because I don't have a problem with your code, other than not knowing if it is three or four digits.

Thanks again,
Robin