Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Also duplicated on Unix and Linux stackexchange site. –  enzotib Feb 11 '12 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 '12 at 11:26
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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