I want to replace string of all js files exsting in directories
export name="test_user" && echo $customerName && sed -i -- 's/this.NAME=""/this.NAME=\"'$name'\"/g' *.js
If I don't use space it works fine but with string above command fails
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Broken down into parts:
"$name", this is the important bit: the variable expansion must be quoted.
Also, if you use
\" in the replacement, and it's in single quotes, then you would insert
", into the result.
You also seem to use a variable called
customerName. I'm assuming this is a typo.
sed that you are using can do in-place editing in the way that you seem to want to do, I don't know.