Bash: dealing with spaces in filenames

Well, this is a n00bish thing but it kind of puzzled me for a while. In a portuguese (either pt-PT or pt-BR) locale Ubuntu installation, and I guess in other distributions, the Desktop folder is inconveniently named ‘Área de Trabalho’. Not only it is a pain in the neck to write it down in the shell, but also when writing bash scripts that will deal with it. However, the solution is simple:

For the first pain in the neck, just link Área de Trabalho to Desktop with:

ln -s Área\ de\ Trabalho/ Desktop

For the second, just escape the variable name enclosing it in commas:

ln -s "$PWD"/cgi-bin $CGI/test

Hope it helps anyone

1 thought on “Bash: dealing with spaces in filenames

Leave a comment