Unix command to escape spaces

后端 未结 7 1358
春和景丽
春和景丽 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:48

    You can use 'single quotes' to operate on a path that contains spaces:

    cp '/path/with spaces/file.txt' '/another/spacey path/dir'

    grep foo '/my/super spacey/path with spaces/folder/*'

    in a script:

    #!/bin/bash
    
    spacey_dir='My Documents'
    spacey_file='Hello World.txt'
    mkdir '$spacey_dir'
    touch '${spacey_dir}/${spacey_file}'
    

提交回复
热议问题