6

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.

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • have you tried - http://stackoverflow.com/questions/3860010/how-do-i-see-see-version-of-tcsh-that-is-running – KevinDTimm Jan 10 '13 at 14:07
  • @KevinDTimm -- SO didn't recommend I look at that when I started posting the question. Unfortunately, `$version` is an undefined variable. – mgilson Jan 10 '13 at 14:11
  • 3
    @closevoter -- I fail to see how this question is off-topic for SO. It is a question about a "software tool commonly used by programmers" that is "based on a problem that I am actually facing". If you disagree, please let me know *why* more specifically. Thanks. – mgilson Jan 10 '13 at 14:25
  • as there doesn't seem to be a reliable test for true csh (Under Sun, I thought there was, but I don't have access o that anymore), AND the only versions for true csh would be vendor specific, maybe you have to invert your test, like 'if (shellTest==tcsh) ; then setup for tcsh ; else if (shellTest==bsd-csh) ; then setup for bsd-csh ; else setup for plain csh ; end if` (sorry if that isn't really csh syntax, for me, it's too long ago ;-) Good luck. – shellter Jan 10 '13 at 15:34
  • @shellter -- Thanks. I'm actually just trying to debug the script. The whole thing is a super complicated mish-mash of scripts that are written in a variety of shell dialects and even some perl to build our code. My script that fails gets sourced at the end of the whole thing to finalize the build process for a particular target machine. It errors out with an error about `:` being an invalid command (even though `:`) does not exist in the file! (although that is a null command in `sh` I believe) And as I said, it works for me -- Apparently I'm using some version of csh -- `bsd-csh` maybe? – mgilson Jan 10 '13 at 15:40
  • The 't' in tcsh stands for TENEX, not taco, but it's usually just referred to as "tcsh" without worrying about what the 't' means. – Keith Thompson Jan 10 '13 at 16:20
  • @KeithThompson -- Sorry, I'm aware that the "t" doesn't in any way mean "taco". It was meant to be a joke -- I like to keep things light. It's a pun based on splitting "tcsh" into "tc" and "sh". Since we all know "sh" is "shell" it's fun to think of "tc" as "taco". But you probably already figured that out ... – mgilson Jan 10 '13 at 16:23
  • 1. hm.. a script in a mish-mash of scripting environment getting **sourced** by [t]csh or other ??? . 2. Noting how tcsh and csh are considered synomomus, when they're not, maybe disambiguating them will help, ie use full paths to the correct underlying shell? 3. I'm almost sure old csh honored ':' as the null command. 4. Don't have any info on bsd-csh, but posting to comp.unix.shell will the the real-old-timers who would know the correct history (not that that will solve your problem!). Good luck! – shellter Jan 10 '13 at 16:27
  • If you're using ubuntu, then your cshell is the OpenBSD version, with a few patches. It has absolutely no support for getting it's version, being that it doesn't encode it's version anywhere. Can't help you beyond that, though. – Anya Shenanigans Jan 10 '13 at 16:30
  • @Petesh -- Thanks. Post that as an answer and I'll probably accept it. (I am using ubuntu, I just didn't think that would be relevant as it seems insane to me that a shell wouldn't encode it's version *somewhere* -- It makes me want to rewrite the whole build system with `bash`). – mgilson Jan 10 '13 at 16:32

3 Answers3

5

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
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • Didn't see your answer immediately. Seems much more precise than mine. +1 – VonC Jan 10 '13 at 19:12
  • I know that my colleagues are running `tcsh` because I can `csh --version` there and find out ;-). My best guess at the problem is that there is a syntax error in there somewhere and `csh` doesn't pick it up because it lacks any formal parser or due to a silly parser "bug" as referenced in your link whereas `tcsh` does see the syntax error and yells at me (but doesn't provide any useful information for debugging). Anyway, nice answer. I'll wait a little longer (just in case), but you're likely to get the accept on this one. – mgilson Jan 10 '13 at 19:16
  • @mgilson: Again, it would be very useful if you could construct a small script (say, half a dozen lines) that works for you and fails for your colleagues, along with the exact error message. As a recovering [t]csh user myself, I'm curious about any incompatibilities. – Keith Thompson Jan 10 '13 at 19:59
  • @KeithThompson -- Yeah. I know. I've been trying to reconstruct this bug in a simple, reproducible manner for a few days now (so far with no success. It's bizarre). As this script is soon to be deprecated, I'm not going to spend too much more time on it. I was just hoping that knowing the csh version would help me find *something*. Congrats for leaving the `[t]csh` world. I very much prefer `bash` ... but in this case I don't have much of a choice. – mgilson Jan 10 '13 at 20:03
3

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.

Pre-defined Variables

The following variables have special meaning to the C Shell.
Of these, argv, csh_version, cwd, home, path, prompt, ROOTDIR, shell, status, COMSPEC, and TMPDIR are always set by the shell.
Except for cwd and status, 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's bsd-csh

... then bsd-csh doesn't seem to support any kind of version feature.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes, I figured that `csh --version` would only work if my csh was actually `tcsh`. Unfortunately, `csh_version` is also an Undefined variable for me: `%echo $csh_version` gives me: `csh_version: Undefined variable` – mgilson Jan 10 '13 at 15:21
  • @mgilson Are you sure your `/bin/csh` (or what `which csh` returns) is not a link to another shell? – VonC Jan 10 '13 at 15:23
  • That is a great question (I don't know why I didn't track this down earlier). `/bin/csh` links to `/etc/alternatives/csh` which links to `/bin/bsd-csh`. Apparently it's `bsd-csh` (although I'm not sure why I would have that on my Ubuntu machine ...)? – mgilson Jan 10 '13 at 15:25
  • *"Otherwise, a `csh` session is supposed to set a variable `$csh_version`."* [Citation needed] -- I've never seen a shell that sets `$csh_version`. – Keith Thompson Jan 10 '13 at 16:17
  • @KeithThompson citation added – VonC Jan 10 '13 at 18:35
2

If you're using Ubuntu, then your csh is the OpenBSD version, with a few patches. It has absolutely no support for getting its version, being that it doesn't encode its version anywhere. Can't help you beyond that, though.

If you've not installed csh on ubuntu, but have installed tcsh, then it will use tcsh as an alias to csh. They are, as you've discovered, mostly compatible.

For yourself, you can probably debug the issue by using update-alternatives to redirect csh to tcsh (as long as you've installed tcsh as well).

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122