I want to replace this string
dh $@
with that one
dh $@ --foobar
I tried this
sed --expression "s/dh $@/dh $@ --foobar/" file
But of course there is the blank and the $ makeing "problems".
Use single quotes around the pattern to avoid shell variable expansion from expanding the $@
to the empty string (or whatever other contents the positional parameters contain.
sed --expression 's/dh $@/dh $@ --foobar/' file
You could also use &
in the replacement to avoid needing to duplicate the pattern. ( &
in the replacement means the entirety of the match.)
sed --expression 's/dh $@/& --foobar/' file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.