2

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.

Rory
  • 33
  • 1
  • 3
  • **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](http://unix.stackexchange.com/q/4899) or [here](http://mywiki.wooledge.org/Quotes)). 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](http://unix.stackexchange.com/q/23390#23390). (Note the double quotes in `"${SMOKE_JMX_LOCATIONS[@]}"`, too) – Gilles 'SO- stop being evil' Oct 27 '11 at 21:50

1 Answers1

2

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
l0b0
  • 50,672
  • 41
  • 197
  • 360