Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to do the following in ksh shell:

JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation

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

cp $SMOKE_JMX_LOCATION /var/tmp

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

1 Answer 1

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:

JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation
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
1  
Zsh is the only shell that I recall coping with null characters. –  Gilles Oct 27 '11 at 21:42

Your Answer

 
discard

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.