Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to do the following in ksh shell:


SMOKE_JMX_LOCATION="$JMX_ROOT/\"Smoke Set\"/*.txt $JMX_ROOT/\"Smoke Set\"/*.TXT 
$JMX_ROOT/\"Smoke Set\"/SmokeSet.jmx"


I.e. copy .txt, .TXT and .jmx files from one directory to another directory but am getting errors because of the spaces in "Smoke Set".

Any help is much appreciated.

share|improve this question
Always put double quotes around variable substitutions and command substitutions ($foo and $(cmd)), unless you understand why not to do it in a particular case (start here or here). So: start with cp "$SMOKE_JMX_LOCATION" /var/tmp, whereupon you realize that you have a single first argument to cp. Then think carefully about what omitting the quotes would do, and you get l0b0's answer. (Note the double quotes in "${SMOKE_JMX_LOCATIONS[@]}", too) – Gilles Oct 27 '11 at 21:50
up vote 2 down vote accepted

You generally can't put several paths in a single string, because anything* which is a valid string is also a valid path in most file systems. You could use an array:

set -A SMOKE_JMX_LOCATIONS "$JMX_ROOT/Smoke Set/"*.txt "$JMX_ROOT/"Smoke Set"/"*.TXT "$JMX_ROOT/Smoke Set/SmokeSet.jmx"
cp "${SMOKE_JMX_LOCATIONS[@]}" /var/tmp

* Before anyone protests about \0 and /, the former can't be part of a variable (at least if ksh works like Bash; couldn't find a reference), and the latter can't be part of file names, but it's very much valid in paths.

share|improve this answer
Zsh is the only shell that I recall coping with null characters. – Gilles Oct 27 '11 at 21:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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