View previous topic :: View next topic |
Author |
Message |
Joe_Sextus n00b

Joined: 28 Feb 2006 Posts: 45
|
Posted: Sat Oct 14, 2006 2:47 pm Post subject: Bash Script Question |
|
|
I have a bash script I wrote handle my kernel compilation and am having a problem with it. If anyone can point out my newb error that would be great. I want it to take parameters like this:
Code: | ./dokernel kernelversion revision [nogrub] |
I am not sure of the syntax of the if statement for string comparison, everything I try either gets me the to the exit everytime, or the else everytime (i.e. with or without nogrub it exits). I know this is just something simple I'm missing, but I am relatively new to bash scripting (This is the most complex one I've written).
Code: | #!/bin/sh
cd linux-$1-gentoo-r$2 &&
make &&
make modules_install &&
cd .. &&
cp -v linux-$1-gentoo-r$2/arch/i386/boot/bzImage /boot/kernel-$1-gentoo-r$2 &&
cp -v linux-$1-gentoo-r$2/.config /boot/config-$1-gentoo-r$2 &&
if [ "$3"="nogrub" ] ; then
exit
else
echo "" >> /boot/grub/grub.conf &&
echo "title=Gentoo $1-r$2 " >> /boot/grub/grub.conf &&
echo "root (hd0,1)" >> /boot/grub/grub.conf &&
echo "kernel /boot/kernel-$1-gentoo-r$2 root=/dev/hda2" >> /boot/grub/grub.conf &&
echo "" >> /boot/grub/grub.conf &&
echo "title=Gentoo $1-r$2 (noX)" >> /boot/grub/grub.conf &&
echo "root (hd0,1)" >> /boot/grub/grub.conf &&
echo "kernel /boot/kernel-$1-gentoo-r$2 root=/dev/hda2 softlevel=noX" >> /boot/grub/grub.conf
fi
|
Thanks,
Joe |
|
Back to top |
|
 |
wynn Advocate


Joined: 01 Apr 2005 Posts: 2421 Location: UK
|
Posted: Sat Oct 14, 2006 3:07 pm Post subject: |
|
|
I think the reason it isn't working as you want is that the "=" in ""$3"="nogrub" should have spaces on each side of it. Bash seems to like its operators separated from other things by spaces, probably because it uses spaces to split the line into 'words'.
You probably don't want the '&&' after the second "cp". _________________ The avatar is jorma, a "duck" from "Elephants Dream": the film and all the production materials have been made available under a Creative Commons Attribution 2.5 License, see orange.blender.org for details. |
|
Back to top |
|
 |
Joe_Sextus n00b

Joined: 28 Feb 2006 Posts: 45
|
Posted: Sat Oct 14, 2006 3:20 pm Post subject: |
|
|
Thanks, I'll try that on the next compile. |
|
Back to top |
|
 |
toralf Developer


Joined: 01 Feb 2004 Posts: 3843 Location: Hamburg
|
Posted: Sat Oct 14, 2006 3:25 pm Post subject: |
|
|
In former times it was better to write instead of only for continuation at the next line |
|
Back to top |
|
 |
wynn Advocate


Joined: 01 Apr 2005 Posts: 2421 Location: UK
|
Posted: Sat Oct 14, 2006 3:30 pm Post subject: |
|
|
You might like to try Code: | if [ "$3" = "nogrub" ] ; then
exit
else
cat >>/boot/grub/grub.conf <<EOF
title=Gentoo $1-r$2
root (hd0,1)
kernel /boot/kernel-$1-gentoo-r$2 root=/dev/hda2
title=Gentoo $1-r$2 (noX)
root (hd0,1)
kernel /boot/kernel-$1-gentoo-r$2 root=/dev/hda2 softlevel=noX
EOF
fi | It's a "Here document", you can find it in the man page but, better by far, Mendel Cooper's "Advanced Bash-Scripting Guide" http://tldp.org/LDP/abs/html/ or emerge app-doc/abs-guide _________________ The avatar is jorma, a "duck" from "Elephants Dream": the film and all the production materials have been made available under a Creative Commons Attribution 2.5 License, see orange.blender.org for details. |
|
Back to top |
|
 |
|