I am using sed to replace a path in a file with new path. What is missing or not right here?
# sed -i `s|/$SPLUNK_HOME/bin/splunk|/opt/splunk/bin/splunk|g' filename
I get > with it.
I am using sed to replace a path in a file with new path. What is missing or not right here?
# sed -i `s|/$SPLUNK_HOME/bin/splunk|/opt/splunk/bin/splunk|g' filename
I get > with it.
You are with the backtick (`) opening a subshell statement which you are never terminating. Make sure your quotes match.
The > prompt is the shell telling you that it is seeking more input for an unterminated quote by presenting you with the secondary prompt defined in PS2.
You want to use parameter expansion inside your script, so the weak quote (") is the quote to use.
For example:
$ cat haystack
I found some straw in here!
$ needle=straw
$ sed "s/$needle/pins/" haystack
I found some pins in here!
Let's take a look at the difference between what happens when you use weak quotes (") and strong quotes ('):
$ set -x
$ sed "s/$needle/pins/" haystack
+ sed s/straw/pins/ haystack
I found some pins in here!
$ sed 's/$needle/pins/' haystack
+ sed 's/$needle/pins/' haystack
I found some straw in here!
As you can see, with weak quotes, the parameter expansion for $needle takes place at the shell's behest before sed ever gets to see it. With strong quotes, this does not happen, so sed is now searching for the regular expression /$needle/, which is "end of input followed by the string needle", which will never match anything, so no substitutions are made.