Tcsh Shell trouble

Need assistance in getting a solution for a TCSH shell environment variable .
I read on internet that leading zeros as octal numbers and redhat doesnt supports octals but Solaris works on TCSH shell. Is there any way we can fix this . All my script has 08 or 09

$ @ x = 5 + 08
@: Badly formed number.
$ @ x = 5 + 8
$

Tcsh version on redhat

$ /bin/tcsh --version
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec

On Solaris box the tcsh version doesnt through this error

$ tcsh --version
tcsh 6.12.00 (Astron) 2002-07-23 (sparc-sun-solaris) options 8b,nls,dl,al,kan,rh,color,dspm,filec

Who knows? The C shell is loopy!

All I see is that on Solaris there is no error, but the result is 13, which is still in base 10.

$ tcsh --version
tcsh 6.17.00 (Astron) 2009-07-10 (i386-sun-solaris) options wide,nls,dl,al,kan,rh,color,filec

% @ x = 5 + 08

% echo $x
13

% printf "%o\n" "$x"
15

You should consider using a better shell.

Scott . I have some old legacy scripts which are running on Solaris so I am migrating it to linux environment . It will be hard to change some 100 scripts to bash . So I need to fix this . I would appreciate if you know which version of TCSH will work on linux

Hi.

I saw that changing:

@ x = 5 + 08

To:

@ x = 5 + 8

fixes the error.

As, on Solaris, either returns 13, which is a decimal number not an octal number, that's what I would do!

Can you show me the result of

@ x = 5 + 08

from your Solaris machine. Perhaps on yours it returns 15 (an octal number)?

On Scientific Linux 6.4, Solaris 11 I have the same version of tcsh (6.17.00 (Astron) 2009-07-10).

$ @ x = 08
@: Badly formed number.
$ uname -a
Linux ramxtxls1153 2.6.32-358.6.2.el6.x86_64 #1 SMP Tue May 14 15:48:21 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
$ tcsh --version
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec
$uname -a
SunOS ramxtxus341 5.10 Generic_127111-09 sun4u sparc SUNW,SPARC-Enterprise
$ @ x = 03
$ tcsh --version
tcsh 6.12.00 (Astron) 2002-07-23 (sparc-sun-solaris) options 8b,nls,dl,al,kan,rh,color,dspm,filec

That's interesting. I'm not sure what I did yesterday, but now (on Solaris 11), I do get an error:

scott@sol11:~$ echo $0
-ksh
scott@sol11:~$ tcsh
> echo $0
tcsh
> @ x = 5 + 08
@: Badly formed number.
> tcsh --version
tcsh 6.17.00 (Astron) 2009-07-10 (i386-sun-solaris) options wide,nls,dl,al,kan,rh,color,filec
>

It's the only version of Solaris I have, but it does have the same version of TCSH (6.17.00) as my RHEL and both give the error. So perhaps it's a "problem" with this version of TSCH (as opposed to 6.12.00 you have on Solaris), or a problem with TCSH on this version (11) of Solaris.

edit: Ah, it seems yesterday, I may have been using CSH, not TCSH. CSH doesn't give the error on Solaris 11, but it still doesn't return an Octal number

1 Like

The problem is that the leading zero causes some versions of tcsh to interpret "08" as octal eight - which is indeed an invalid octal number.

Download and install tcsh-6.18.01. That version has the behavior you want. You may have to build it from source.

1 Like

Posix, in their wisdom mandated that shells should follow this rule... "Only the decimal-constant, octal-constant, and hexadecimal-constant constants specified in the ISO C standard, Section 6.4.4.1 are required to be recognized as constants". For some reason, shells that are totally non-posix in nature like csh and tcsh are adopting this rule. It has broken a lot of scripts including several hundred of my own. I fixed them all rather than fighting it. But I use ksh which can easily strip off the leading zero. There is no great solution to offer someone who has a lot of csh scripts.

There is no easy way to say this, but if you insist on creating lots of csh scripts you better prepare yourself to face problems with no good solutions. The right answer is to write your scripts in bash or ksh. I know you don't want to hear that, but it's the truth.

Thank you Scott ,fpMurphy,Perderabo. I will be installing the latest versin 6.18 and see if it gets fixed .

---------- Post updated 04-01-14 at 09:41 AM ---------- Previous update was 03-31-14 at 11:17 AM ----------

fpmurphy

is tcsh 6.18 version available on internet for 64bit RHEL 2.6