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
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.
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"