简体   繁体   中英

Ability to use variable in bash SED

I'm trying to use sed to add a variable prefix to my command...

datestamp="$(date +'%D %r %Z')"
prefix=$("$datestamp site=$i space=$number")

prefix=$("site=$i space=$number")
echo test this thing | sed 's/^/$prefix /'

I'm expecting site=abc space=12 test this thing

Simply replace the single quotes for the sed line with double quotes, and that should do the trick.

datestamp="$(date +'%D %r %Z')"
prefix="$datestamp site=$i space=$number"
echo test this thing | sed "s@^@$prefix @"

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM