Bash scripting worries
delgarde at ihug.co.nz
Mon Apr 2 01:16:01 PDT 2007
On Sun, 2007-04-01 at 09:51 +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
> 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.
Actually, it's simpler than that. Remember, environment variables like
$NODE are expanded by the shell *before* the command is actually run, so
the command you're running is actually something like this:
sed "s/DRIVE//dev/hda3//" ...
All the extra '/' characters from the file paths are confusing sed.
To work around it, you can actually use characters other than '/' as
separators in the regex. I find '@' is a good one when dealing with file
paths, as it's unlikely to ever appear in a file name. For example
sed "s at DRIVE@$NODE@" ...
should work fine, as it will end up as the perfectly valid expression:
sed "s at DRIVE@/dev/hda3@" ...
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 189 bytes
Desc: This is a digitally signed message part
More information about the blfs-support