I don't have any experience writing .sh files. I want to run the pvm2raw utility of this app from the Volume Library.

I get the following error when running build.sh in Ubuntu 10.10.

enter image description here

build.sh is as follows:

# make command
set mmfile=V3Makefile
set make="make -f $mmfile"

set rule=$1
if ($rule == "") set rule="all" // line 16

if ($rule == "deps") then
   if ($HOSTTYPE == "i386") $make MAKEDEPEND="c++ -M -I/usr/X11R6/include" OPTS="-DHAVE_CONFIG_H -DVIEWER_HAVE_DCMTK" TARGET=LINUX depend

What's wrong there?

Edit: I followed jw013's advice and installed csh. Now I get the following error:

enter image description here

How can I solve this Undefined variable problem?

  • 2
    Slightly off-topic, but eww, a csh script? It seems so ... primeval.
    – jw013
    Feb 11 '12 at 5:08
  • 1
    A csh script named build.sh? Double eww. Feb 11 '12 at 23:41
  • You must have run it as sh ./build.sh. If you had run it as ./build.sh, you would have gotten a different error message. Feb 11 '12 at 23:49
  • 1
    i'm curious why you posted screenshots of your terminal rather than simply copying and pasting.
    – ixtmixilix
    Feb 12 '12 at 0:57
  • 1
    Text is always preferred over images, in regards to stdout/stderr. Text can be indexed. Feb 12 '12 at 21:35

The script is declared as

#!/bin/csh -f

The syntax also matches that of csh. You are running it as

sh build.sh

Since csh is compatible with neither Bourne nor POSIX sh, the mismatch causes lots of syntax errors. The correct way to run build.sh is either

csh build.sh

or by making it executable (chmod +x build.sh) and running it directly, letting the system choose the correct interpreter according to the shebang (#!) line:


(assuming it's in your current directory).

The HOSTTYPE variable is only defined in tcsh, which is one of the csh implementations. If csh is some other csh implementation on your machine, make sure that you install tcsh, and run

tcsh build.sh

or change the first line of the script to #!/bin/tcsh -f.

  • Thanks; I installed csh via apt-get, but got this:csh build.sh HOSTTYPE: Undefined variable. Any ideas? Feb 11 '12 at 6:18
  • 1
    HOSTTYPE is automatically set by most shells. I'm not sure why it is not set for you - maybe you could make a new question for this. Post your shell version and relevant details about your environment.
    – jw013
    Feb 11 '12 at 6:44
  • 1
    @omgzor There are two implementations of csh: the original C shell by Bill Joy, and the more recent and more featureful tcsh. Only tcsh defines HOSTTYPE (​@jw013: and bash, following tcsh). This script assumes that /bin/csh is the tcsh implementation. Feb 11 '12 at 23:34
  • The #!/bin/csh -f isn't in the snippet that the OP posted, but it is in the build.sh script for the app. I was going to mention that build.sh is a poor name for a csh script, but that's the fault of the app developer, not of the original poster. Feb 11 '12 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.