Main concept is
I intend to get current directory of my script file.
This script file will be copied to /etc/init.d.
A string in this copy will be replaced with current directory value.
Below is original script file:
current_dir=$(pwd)
cp $current _dir/myScript /etc/init.d/myService
sed -i 's/$(pwd)/$current_dir/g' /etc/init.d/myService
I keep on got error on passing $pwd to sed... please advise...
I have tested and tried to edit my script with yout advice.. but still unable to get the value of PWD to replace my copy of shell script.
I have 2 shell script, a.sh and b.sh.
a.sh will make a copy of b.sh at /etc/init.d and will replace the "$PWD" keyword in the copy of b.sh.
Below is the edited code for my scripts:
a.sh
current_dir="$PWD"
echo $current_dir
cp $current_dir/b.sh /etc/init.d/copyOfb.sh
sed -i 's/$PWD/"$current_dir"/g' /etc/init.d/copyOfb.sh
b.sh
current_dir="$PWD"
echo $current_dir
when i execute the a.sh... the keyword PWD in copy of b.sh is replaced with the string "$current_dir"
and eventually i have this
current_dir=""$current_dir""
in my copyOf b.sh....
I tried to manipulate the quotes.. but still unable to get the thing right...
sed -i "s/$PWD/"$current_dir"/g" /etc/init.d/copyOfb.sh
before
but i got this error message:
sed: -e expression #1, char 9: unknown option to `s'
Then i tried with your advise,
sed -i "s|$PWD|\"$current_dir\"|g" /etc/init.d/copyOfb.sh