How to remove extra spaces in bash?

后端 未结 10 1769
说谎
说谎 2020-12-01 05:46

How to remove extra spaces in variable HEAD?

HEAD=\"    how to  remove    extra        spaces                     \"

Result:

10条回答
  •  余生分开走
    2020-12-01 06:11

    I would make use of tr to remove the extra spaces, and xargs to trim the back and front.

    TEXT="     This          is  some                             text   "
    echo $(echo $TEXT | tr -s " " | xargs)
    
    # [...]$ This is some text
    

提交回复
热议问题