如何使用bash脚本回显一个或多个制表符? 当我运行这段代码时
res=' 'x # res = "\t\tx"
echo '['$res']' # expect [\t\tx]
我明白了
res=[ x] # that is [<space>x]
如何使用bash脚本回显一个或多个制表符? 当我运行这段代码时
res=' 'x # res = "\t\tx"
echo '['$res']' # expect [\t\tx]
我明白了
res=[ x] # that is [<space>x]
当前回答
res="\t\tx"
echo -e "[${res}]"
其他回答
echo -e ' \t '
将回显'space制表符换行符' (-e表示'启用反斜杠转义'):
$ echo -e ' \t ' | hexdump -C
00000000 20 09 20 0a | . .|
你需要为echo使用-e标志
echo -e "\t\t x"
把你的字符串放在双引号之间:
echo "[$res]"
你也可以试试:
echo Hello$'\t'world.
使用echo打印变量值是一个常见的Bash陷阱。 参考链接:
http://mywiki.wooledge.org/BashPitfalls#echo_.24foo