Currently in my bashrc I export a variable export dl="path/to/Downloads". The path contains a space in it so whenever I mv something from the directory, I have to quote the dl variable such as mv "$dl"/*.py somewhere/else. Is there any way I can define the variable dl in a way that I don't have to quote it in the command line, i.e., in a way that I could just do mv $dl/*.py somewhere/else?

I've seen similar questions asked on here but haven't been able to find a solution to this specific problem, so pardon me if it's a duplicate post.

  • I don't think so. You have to double-quote it, otherwise, it will split. – annahri Nov 6 '20 at 6:47

No you can't. You can use another shell language, create a symlink without spaces to that dir, or use some alias trickery.

I personally would not do the latter, since I will soon forget about it ;-)

But here is an example, anyway:

# usage: q cmd ...
# just like cmd ..., only without IFS splitting
alias q='_q=$(fc -nl -0); IFS= eval "${_q#*q}" #'

$ src='foo bar' dst='baz quux'
$ q mkdir -p $src/dir $dst
$ q mv $src/dir $dst
$ q ls $dst

  • Perfect, exactly what I wanted! – Revoltechs Nov 6 '20 at 2:21

Not your question exactly, but if your problem is explicitly with a common operation moving files from the Downloads folder you could use an specific alias for that:

alias dl-mv='mv "$dl"/'

Of course, you could rename/change the location of Downloads folder as well (or use a symlink with no spaces on its path).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.