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 but keep getting cannot stat message for the cp command:

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

SMOKE_JMX_LOCATION=$JMX_ROOT/"Smoke Set"/*.*

cp $SMOKE_JMX_LOCATION /var/tmp/tempor

Any ideas? I have tried putting quotes around the various variables but with no luck.

share|improve this question
1  
Note the *.*. I don't know enough of the Korn shell, but in Bash, this would require arrays: SMOKE_JMX_LOCATION=("$JMX_ROOT/Smoke Set"/*.*) followed by cp "${SMOKE_JMX_LOCATION[@]}" /var/tmp/tempor. –  janmoesen Oct 27 '11 at 13:18
    
also exists on stackoverflow –  glenn jackman Oct 27 '11 at 14:19

3 Answers 3

cp "$SMOKE_JMX_LOCATION" /var/tmp/tempor
#--^-------------------^

EDIT: I didn't really notice the wildcards. Yes, quoting them will prevent expansion. Is there any reason you need to put them in a variable? Surely this would work:

cp $JMX_ROOT/"Smoke Set"/*.* /var/tmp/tempor
share|improve this answer
    
Wouldn't work, thanks anyway –  Rory Oct 27 '11 at 13:12
    
Could you expand on "wouldn't work"? Copy-paste your commands and error messages, please. –  janmoesen Oct 27 '11 at 13:16
    
Couldn't get it to work as is, so changed it to the following.. SMOKE_JMX_LOCATION=$JMX_ROOT/Smoke*/*.* I.e. used a wildcard instread of including the space –  Rory Oct 27 '11 at 13:24
    
@Rory, what he gave you is the correct solution (in the edit part at least), youre doing something else wrong, but we cant help unless you give us your commands and errors as requested. –  Patrick Oct 27 '11 at 13:52
SMOKE_JMX_LOCATION="$(echo $JMX_ROOT/"Smoke Set"/*.*)"
cp "$SMOKE_JMX_LOCATION" /var/tmp/tempor
share|improve this answer

You can use an alternate field separator to work around that white space in the directory name.

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

OLD_IFS="$IFS"
IFS=$'\n'

SMOKE_JMX_LOCATION="${JMX_ROOT}/Smoke Set"

cp ${SMOKE_JMX_LOCATION}/*.* /var/tmp/tempor

IFS=$OLD_IFS
share|improve this answer

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.