variable replacement

hi all ,

i want a command that interacts with the input of a user .
i.e.
i want it to serch a file for the first occurance of a variable and replace the value that is after the equal sign .
for example :

my file contains a varible that is $HOME=/home
i want to search for variable $HOME and replace the /home with some input .

thanks
cheers

...
input="x"
while [ -z "$input" ] ; do
input=""
read input
if [ -n "$input" ] ; then
sed '/\$HOME=/ {; s/=.*$/='"$input"'/; q; }' file > file.new
fi
done
...

just enter an empty string to leave the loop.

bakunin

things didnt work as i wanted
i have done the following

the script will prompt for the new path and then read it after that he will search the file and replace this variable ....
this is a kind of cotumization .

input="/home
while [ -z "$input" ] ; do
input=""
echo "please enter the location:\c"
read input
if [ -n "$input" ] ; then
sed '/\$HOME=/ {; s/=.*$/='"$input"'/; q; }' /file > /file.new
fi
done
NOTE : iam using ksh , Solaris 9 over sparc

sorry, I tripped over my own (sed-)foot. ;-))

The sed-script will terminate after the first occurrence of "home=..." and hence the lines following will be lost from the output file.

replace the then ... fi -part with the following:

iFirst=$( print - 'g/^[<blank><tab>]\'$input'/n' |\
ed - file |\
sed '1 s/<tab>.
$//; 2,$d' \
)
sed $iFirst' s/=.*$/='"$input"'/' file > file.new

iFirst is a variable holding the first occurrence of your search string. You will have to replace <blank> and <tab> by real tabs and blanks.

bakunin

sorry, not working

input="/home
while [ -z "$input" ] ; do
input=""
echo "please enter the location:\c"
read input
if [ -n "$input" ] ; then
iFirst=$( print - 'g/^[<blank><tab>]\'$input'/n' |\
ed - file |\
sed '1 s/<tab>.
$//; 2,$d' \
)
sed $iFirst' s/=.*$/='"$input"'/' file > file.new
fi
done

i have treid to modify it ut with little luck ...

thanks for ur help