Make cd command work with spaces Some archives contain folders with spaces in their name.
Sometimes while I'm browsing these folders, I want to open a terminal in current position, so I copy the path to paste it after a cd command.
Of course when there are spaces in the path, cd won't work unless all spaces are escaped.

Since I find it annoying not to be able to paste paths after cd, I just added this function to my .bash_aliases:

function cd {
  if [ -z "$*" ]; then
    command cd
  else
    command cd "$*"
  fi
}


So mkdir "an awful dir name" &amp;&amp; cd an awful dir name now works as expected (what else should cd an awful dir name do?).

Since .bash_aliases shouldn't affect non-interactive shells, other scripts should still work with builtin cd.

Now the question is: can this trick cause problems on my shell? Or am I freaking out for no reason?
Throw away your current code. Instead write this:

for dir in *; do
  (cd "./$dir" &amp;&amp; echo "In $(exec pwd) now.")
done


As a general rule, always put variables into quotes.

Rationale: Your current code can handle a few cases properly, but some other special characters will still be interpreted specially by the shell and lead to unexpected behavior. Therefore the proper way to work around this problem is to write cd ' into the terminal, then to paste the path and then to finish the command by typing '. This will work for all characters except single quotes.

Alternatively, you could invent a command cdclip that changes to the path in the clipboard. Cygwin has /dev/clipboard, and on native Linux there is probably some similar way to read the clipboard contents.