How to add path with space in Bash variable

后端 未结 2 1743
别那么骄傲
别那么骄傲 2020-12-06 16:28

How can I add a path with a space in a Bash variable in .bashrc? I want to store some variables in .bashrc for paths and I encountered a path with

相关标签:
2条回答
  • 2020-12-06 17:13
    mount /dev/sda9 "$games"
    

    As mentioned, always quote variable dereferences. Otherwise, the shell confuses the spaces in the variable's value as spaces separating multiple values.

    0 讨论(0)
  • 2020-12-06 17:14

    When variable contains spaces, variable expansion and then word splitting will result to many arguments, echo command will display all arguments but other program or function may handle arguments another way.

    Surrounding variable with double quotes will prevent arguments to be splitted

    printf "'%s'\n" $games
    
    printf "'%s'\n" "$games"
    
    0 讨论(0)
提交回复
热议问题