Code goes below:
#!/bin/bash
wd1="hello"
wd2="world"
cat >> log.txt <<<"$wd1\t$wd2\n\n"
When I run the above script, '\t','\n' were not expanded at all. So I altered it to this:
cat >> log.txt <<<$(echo -e "$wd1\t$wd2\n\n")
But '\t','\n' are still not expanded. Why?
From
info bash:<<<"$wd1\t$wd2\n\n"is subject to bash expansions but there is no standard expansion for\tor\n. That’s why it doesn’t happen.<<<$(echo -e "$wd1\t$wd2\n\n")doesn’t work because it is unquoted.echooutputs the special characters but then bash does field splitting and they got replaced by spaces.You just need to quote it: