Unix command to escape spaces

后端 未结 7 1357
春和景丽
春和景丽 2020-12-14 07:21

I am new to shell script. Can someone help me with command to escape the space with \"\\ \". I have a variable FILE_PATH=/path/to my/text file ,
I want to escape the spa

7条回答
  •  一整个雨季
    2020-12-14 07:56

    FILE_PATH=/path/to my/text file
    FILE_PATH=echo FILE_PATH | tr -s " " "\\ "
    

    That second line needs to be

    FILE_PATH=echo $FILE_PATH | tr -s " " "\\ "
    

    but I don't think it matters. Once you have reached this stage, you are too late. The variable has been set, and either the spaces are escaped or the variable is incorrect.

    FILE_PATH='/path/to my/text file'

提交回复
热议问题