Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Bash Script Question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Joe_Sextus
n00b
n00b


Joined: 28 Feb 2006
Posts: 45

PostPosted: Sat Oct 14, 2006 2:47 pm    Post subject: Bash Script Question Reply with quote

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
View user's profile Send private message
wynn
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2421
Location: UK

PostPosted: Sat Oct 14, 2006 3:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
Joe_Sextus
n00b
n00b


Joined: 28 Feb 2006
Posts: 45

PostPosted: Sat Oct 14, 2006 3:20 pm    Post subject: Reply with quote

Thanks, I'll try that on the next compile.
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3843
Location: Hamburg

PostPosted: Sat Oct 14, 2006 3:25 pm    Post subject: Reply with quote

In former times it was better to write
Code:
&&\
instead of only
Code:
&&
for continuation at the next line
Back to top
View user's profile Send private message
wynn
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2421
Location: UK

PostPosted: Sat Oct 14, 2006 3:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum