简体   繁体   中英

Bash command in a variable without executing

I have two commands which I want to close in variables:

val=`awk -F "\"" '{print $2}' ~/.cache/wal/colors-wal-dwm.h | sed -n -e 1,3p -e 5,7p`
dummy=`printf "dwm.normfgcolor:\ndwm.normbgcolor:\ndwm.normbordercolor:\ndwm.selfgcolor:\ndwm.selbgcolor:\ndwm.selbordercolor:")`

They basically print some stuff. I want to merge the output with paste command (this doesn't work):

paste <($dummy) <($val)

I wanted to avoid temp files but at this point I'm out of ideas. Thanks in advance.

$dummy

Is a variable, not a command to execute. echo is a command. printf is another command.

paste <(echo "$dummy") <(echo "$val")

Do not use backticks - $(..) instead. Check your scripts with shellcheck. You code is somewhat unreadable to me... if you don't care about variables, just don't use them.

awk -F '"' '{print $2}' ~/.cache/wal/colors-wal-dwm.h |
sed -n -e 1,3p -e 5,7p |
paste <(
     printf "dwm.%s:\n" \
        "normfgcolor" \
        "normbgcolor" \
        "normbordercolor" \
        "selfgcolor" \
        "selbgcolor" \
        "selbordercolor"
  ) -

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