Home > Enterprise >  Bash command in a variable without executing
Bash command in a variable without executing

Time:07-20

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.

CodePudding user response:

$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"
  ) -
  • Related