如何使用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]
当前回答
如果你想在脚本中使用echo "a\tb",你可以这样运行脚本:
# sh -e myscript.sh
或者,您也可以将执行权限赋予myscript.sh,然后运行脚本。
# chmod +x myscript.sh
# ./myscript.sh
其他回答
你需要为echo使用-e标志
echo -e "\t\t x"
把你的字符串放在双引号之间:
echo "[$res]"
如果你想在脚本中使用echo "a\tb",你可以这样运行脚本:
# sh -e myscript.sh
或者,您也可以将执行权限赋予myscript.sh,然后运行脚本。
# chmod +x myscript.sh
# ./myscript.sh
res="\t\tx"
echo -e "[${res}]"
你也可以试试:
echo Hello$'\t'world.