I'm having problems with sed. I can't seem to get this to work.
I have a data file (renegade.dat), which contains the following lines:
/opt/rg/data/
/opt/rg/misc/
/opt/rg/menu/
/opt/rg/logs/
/opt/rg/msgs/
/opt/rg/temp/
/opt/rg/prot/
/opt/rg/arcs/
I want to be able to change those to a variable read by "read directory".
Here is my code:
#!/bin/bash
clear
echo "Renegade Version 1.10 Install Utility"
echo
echo 'This utility will install Renegade BBS Version 1.19/Alpha.'
echo 'Please make sure that UNZIP and this file are located'
echo 'in the same directory as the archive RGV110.ZIP.'
echo
echo 'You will only be asked to enter the main path for the BBS'
echo 'directory.'
echo
echo 'Install Renegade BBS Version 1.10? '
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo Yes
echo 'Please enter main path for the bbs Example: /opt/rg'
echo ':'
stty onlcr
read directory
unzip -o rgv10.zip *.rgd -d $directory
unzip -o $directory/bbs.rgd -d $directory
unzip -o $directory/arcs.rgd -d $directory
unzip -o $directory/bbs.rgd -d $directory
unzip -o $directory/data.rgd -d $directory
unzip -o $directory/door.rgd -d $directory
unzip -o $directory/menu.rgd -d $directory
unzip -o $directory/misc.rgd -d $directory
unzip -o $directory/prot.rgd -d $directory
sed -i "s/\/opt\/rg/$directory" "$directory/renegade.dat"
rm $directory/*.rgd
else
echo No
fi
The sed -i "s/\/opt\/rg/$directory" "$directory/renegade.dat"
blurb doesn't appear to be working.
Anyone know what i'm doing wrong?
Thanks.
/
. Does$directory
also contain slashes? regardless, I'd suggest using a different sed delimiter. See for example Use sed to replace a string with one containing a directory name (i.e. a slash "/") – steeldriver Jan 26 '24 at 02:30sed -i "s,\/opt\/rg\/,/$directory/,g" "$directory/renegade.dat"
Getting closer. – ignatius Jan 26 '24 at 02:57"s,/opt/rg/,$directory,"
– steeldriver Jan 26 '24 at 03:08