Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions about general computing hardware and software on Stack Overflow. You can edit the question so it’s on-topic for Stack Overflow. Closed 1 year ago. Improve this question
I'm trying to use
sed -i -e "s/.*seb.*/ \"$ftp_login_template\"/" $ftp_dir
however I get this error:
sed: -e expression #1, char 34: unknown option to `s'
I don't understand why since this works perfectly:
sed -i -e "s/.*wbspassword.*/ \"wbspassword\": \"$password\",/" $user_conf
Any ideas as to what I'm doing wrong?
Could this be the problem? ftp_login_template=\${user}:${password}:24:86::\/var\/lib\/clit.${user}\/downloads:\/bin\/false\"
The problem is with slashes: your variable contains them and the final command will be something like sed "s/string/path/to/something/g"
, containing way too many slashes.
Since sed
can take any char as delimiter (without having to declare the new delimiter), you can try using another one that doesn't appear in your replacement string:
replacement="/my/path"
sed --expression "s@pattern@$replacement@"
Note that this is not bullet proof: if the replacement string later contains @
it will break for the same reason, and any backslash sequences like \1
will still be interpreted according to sed
rules. Using |
as a delimiter is also a nice option as it is similar in readability to /
.
Success story sharing
g
)."
not'
otherwise you'll get a lot of$content
in your end result instead of the content of$content
:) )sed -i "s/../../g"
with different character i.e:sed -i "s@...@...@g"
, then the problem of multiple slashes should disappear. And if you use"
instead of'
it should also works well with variables inside, i.e.:export var1=bar; sed -i "s@foo@${var1}@g"
. More info you can find into awesome sed documentation: grymoire.com/Unix/Sed.htmlinfo sed
(source: unix.stackexchange.com/questions/259083/…): "The syntax of the s (as in substitute) command is ‘s/regexp/replacement/flags’. The / characters may be uniformly replaced by any other single character within any given s command."