Echo tab characters in bash script

后端 未结 10 2133
予麋鹿
予麋鹿 2020-12-07 08:09

How do I echo one or more tab characters using a bash script? When I run this code

res=\'       \'x # res = \"\\t\\tx\"
echo \'[\'$res\']\' # expect [\\t\\tx         


        
10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 08:42

    From the bash man page:

    Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.

    So you can do this:

    echo $'hello\tworld'
    

提交回复
热议问题