On Fri, 2007-03-30 at 09:49 +0100, Kevin Annies wrote: > Hi, > > I am trying to convert grub hard drive definitions (as part of an > installation script) > > There a several issues. Below is a section of the code: > ---------------------------------------------------------- > echo "please enter the root partition drive ie; hda, hdb, sda,sda" > read DISK > > if [ $DISK = "hda" ] > then > export GRUB=hd0 > elif [ $DISK = "hdb" ] > then > export GRUB=hd1 > elif [ $DISK = "sda" ] > then > export X=2 > if [ -f /dev/hdb ] > then > $X = $X - 1 > fi > > export GRUB=hd$X > else > export X=3 > if [ -f /dev/hdb ] > then > $X = $X - 1 > fi > > export GRUB=hd$X > fi > > echo $GRUB > echo "please enter the partition number without the prefix ie; instead > of hdb4, just type 4" > read PARTITION > > $PARTITION = $PARTITION - 1 #line 130 > export NODE = "$GRUB,$PARTITION" #line 131 > echo $NODE > > ---------------------------------------- > when executed I recieve this output: > -------------------------------------------------------- > please enter the root partition drive ie; hda, hdb, sda,sda > sda > hd2 > please enter the partition number without the prefix ie; instead of > hdb4, just type 4 > 3 > ./INSTALLATION: line 130: 3: command not found > ./INSTALLATION: line 131: export: `=': not a valid identifier > ./INSTALLATION: line 131: export: `hd2,3': not a valid identifier
Easy fix. Repeatedly, you've used commands like "$X = $X -1". This won't
work, since by prefixing the first X with the $ sign, you're evaluating
it, and trying to set the result to something else. Also, you can't do
subtraction quite that easily, since all BASH sees in this case is text.
What you actually want is something like:
X=$((X-1))
or
PARTITION=$((PARTITION-1))
Note three things. a) The value on the left doesn't have a $ sign in
front of it. b), there's no whitespace on either side of the = sign. And
c), the use of $((...)) marks, which tells bash that the contents should
be evaluated as a math expression.
That covers the problems on line 130. The ones on 131 are probably for
the second reason - i.e the spaces around the = sign. It needs to
instead be:
export NODE="$GRUB,$PARTITION"
The reason for this is that each parameter to export must be either
simply the name of an existing variable, or an assignment. By putting
spaces in, you're splitting the latter into three instances of the
former, so it tries to export variables called 'NODE', '=', and 'hd2,3'.
For tips on bash scripting, try the following links:
* Advanced Bash Scripting Guide - http://tldp.org/LDP/abs/html
* Wikipedia page - http://en.wikipedia.org/wiki/Bash
Simon.
signature.asc
Description: This is a digitally signed message part
-- http://linuxfromscratch.org/mailman/listinfo/blfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page
