0

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 == "iris4d") $make MAKEDEPEND="CC -M" OPTS="-DHAVE_CONFIG_H -DVIEWER_HAVE_DCMTK" TARGET=IRIX depend
   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 kniwor's advice and installed csh. Now I get the following error:

enter image description here

How can I solve this Undefined variable problem?

2
  • Also duplicated on Unix and Linux stackexchange site.
    – enzotib
    Feb 11, 2012 at 6:36
  • Apparently it expects a HOSTTYPE variable to be passed on via the environment, so try giving it one, e.g. HOSTTYPE=i386 csh build.sh
    – geirha
    Feb 12, 2012 at 11:26

2 Answers 2

2

That looks like a c-shell script. Use

sudo apt-get install csh

and then try running the script in the c-shell. You can open the c-shell by running csh from the bash shell.

1

It is good form and reduces confusion to start all shell scripts by declaring the shell in which they should run. The first line for a Borne shell (what you called ".sh") is "#!/bin/sh". That helps remove all confusion over which shell as each has nuances in its syntax and command structure.

For a Borne shell, the if command looks more like this: if [ $rule = "deps" ]; then # process based on HOSTTYPE fi

A couple other suggestions, they may not be an issue here, but can bite you over time.

1- define a consistent variable naming convention like all uppercase so you can read the code and identify variables easier. 2- Use the curly braces to refer to variables so they cannot get "confused". 3- When comparing strings, put your variables in quotes too.

So lets change the first line from

if ($rule == "") set rule="all"

to

if [ "${rule}XXX" = "XXX" ]; rule="all"

The curly braces protect the confusing with the XXX, that syntax says the value of the variable "rule" with "XXX" appended to the end. So if the result is only XXX then you know that the variable was empty or null.

For the hosttype, you can try adding another line like you have for rule:

set HOSTTYPE=$2

and then when you start the script add a second parameter where you enter the hosttype, e.g. build.sh deps i386

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .