Bash scripting worries

Ken Moffat ken at linuxfromscratch.org
Sun Apr 1 06:15:10 PDT 2007


On Sun, Apr 01, 2007 at 09:51:43AM +0100, Kevin Annies wrote:
> 
> I now wish to use the $NODE variable in a sed command to modify the word 'DRIVE' in menu.lst,
> I used the following command:
> sed "s/DRIVE/$NODE/" /etc/install/lfsmenu.lst > /home/TEMP/boot/grub/menu.lst
> 
> ******************************
> # The first entry is for LFS.
> title Coventry University Linux
> root (DRIVE)
> kernel /boot/lfskernel-2.6.16.27 root=/dev/ROOT
> ***************************************
> 
> I used a similar command to modify the last word 'ROOT' and it works fine. However DRIVE refuses to change and I have a suspicious feeling its because of the brackets it's enclosed by. What regular expression techniques would you suggest I use to get round this?

 Please follow the list etiquette - lines of about 70 characters,
and trimming the unnecessary parts of what you are replying to, as
well as replying belo what you quote.  Thanks.

 Sed can be problematic.  The easiest way is to copy the example
text to a file you can work on, then try variations.  For me, with
only 'root (DRIVE)' in a testfile, your sed works so the problem
might be elsewhere (a typo, or giving the wrong filename).  More
generally, I play around with backslash (\) escapes, type of quoting
(' or "), and sometimes I see if I can use a different pattern, e.g.
'.' for 'exactly one character' to skip over things I think might be
troublesome, so s"/.DRIVE./($NODE)" if the parentheses were the
problem.  The other thing to consider is whether you are going to
accidentally change another line that happens to match the regex. 

HTH
Ken
-- 
das eine Mal als Tragödie, das andere Mal als Farce



More information about the blfs-support mailing list