I have some code which works for me, but when I gave it to some colleagues, it broke. They're using tcsh
whereas, as far as I can figure, I'm using csh
.
I've tried:
csh -v
csh --version
csh -V
csh --help
csh -h
with no success (they all just take me straight to the interpreter prompt). I've also grepped the man page for the string "version", but I didn't come up with anything useful there either. Is there a way to determine the version of csh
that I have installed?
-- Edit --
Following the symbolic links from /bin/csh
, they seem to terminate at /bin/bsd-csh
which seems to imply that I'm using some BSD flavor csh shell if that helps anyone. Also, I'm using ubuntu linux.
Use /proc/self/exe --version . This reflects your login shell -- not the currently running shell.
There are a variety of shells and some have more bells and whistles than others. The 3 most common shells are sh (the original, also known as the Bourne shell), csh (Command SHell) and tcsh (an enhanced version of csh).
Description. The C shell is an interactive command interpreter and a command programming language that uses syntax similar to the C programming language. The shell carries out commands either interactively from a terminal keyboard or from a file. The csh command invokes the C shell.
In comments, you've indicated that you're on Ubuntu, and that /bin/csh
is a symlink to /etc/alternatives/csh
, which is a symlink to /bin/csh
.
The csh
shell originated on BSD Unix, so it's not surprising that csh
is an indirect symlink to /bin/bsd-csh
. It goes back to 1978 or so, before it became common for Unix program to report their own version numbers.
Since you're on Ubuntu, this:
dpkg -l csh
should tell you what version you have -- though the version number of the Debian/Ubuntu package isn't likely to be more useful than the information you already have. And the relationship between the package version number and the version of the shell isn't entirely clear.
I'm assuming that's the right package name. If not, try dpkg -S /bin/bsd-csh
.
You can tell whether you're running tcsh
or not, like this:
if ($?tcsh) then
echo This is tcsh
else
echo This is csh, not tcsh
endif
tcsh
is supposed to be backward compatible with csh, with some extra features, mostly for interactive use. A script written for tcsh could easily fail under csh if it uses tcsh-specific features, but I'd expect tcsh to be able to handle a csh script. As the tcsh(1)
man page says:
tcsh is an enhanced but completely compatible version of the Berkeley UNIX C shell, csh(1).
I understand you probably can't post the entire failing script, but can you post a small representative example that works for you and fails for your colleagues?
One solution might be to ask you colleagues to install vanilla csh
on their systems; they can still use /bin/tcsh
as their interactive shell if they like, but #!/bin/csh
would then cause the script to be executed by the old csh, not tcsh.
Finally, I can't answer a question about [t]csh scripting without adding a link to this.
Addendum: I have access to a Solaris system with a /bin/csh
that isn't tcsh; I can run some simple tests there if you like. One data point: both /bin/tcsh
and /bin/csh
accept :
as a null command, but with /bin/csh
it doesn't accept arguments:
% :
% arg
:: Too many arguments
csh --version
would work only if csh
is actually a symlink to... /bin/tcsh
(!)
Otherwise, a csh
session doesn't seem to set any version, except in this MKSToolkit, where that csh
is supposed to set a variable $csh_version
.
The following variables have special meaning to the C Shell.
Of these,argv
,csh_version
,cwd
,home
,path
,prompt
,ROOTDIR
,shell
,status
,COMSPEC
, andTMPDIR
are always set by the shell.
Except forcwd
andstatus
, this setting occurs only at initialization; these variables are then not modified unless done explicitly by the user.
See this dotfile for instance:
shell_is_csh () { return [ -n "$csh_version" ]; }
/bin/csh
links to/etc/alternatives/csh
which links to/bin/bsd-csh
.
Apparently it'sbsd-csh
... then bsd-csh
doesn't seem to support any kind of version feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With