LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cp $var1 var2 doesn't work (https://www.linuxquestions.org/questions/linux-newbie-8/cp-%24var1-var2-doesnt-work-4175534818/)

johnty 02-22-2015 07:37 PM

cp $var1 var2 doesn't work
 
I'm running a bash script on a Raspberry Pi to control LED pixels. I'm stuck on a basic copy command.

I have a variable called nexttemp which contains the string B_254_TieDyeKaleidoscope.fseq

That file, in the same directory, is a large binary file that I'm trying to copy to a file called MasterFseq.fseq

If I do a

cp nexttemp MasterFseq.fseq

then MasterFseq.fseq contains the B_254_TieDyeKaleidoscope.fseq file name.

I want instead to have copied the binary file to MasterFseq.fseq.

It's my understanding that a $nexttemp will point to the binary file and not the name of it but when I do a

cp $nexttemp MasterFseq.fseq

the $nexttemp is thrown away and I'm told there is no destination file name, eg.

root@FPP:/home/pi/media/sequences# echo cp $nexttemp MasterFseq.fseq
+ echo cp MasterFseq.fseq
cp MasterFseq.fseq

How do I get the binaray file, which is named in nexttemp, copied to MasterFseq.fseq?

John

syg00 02-22-2015 07:53 PM

Looks like you have a file called nexttemp, not a variable.
What does "echo $nexttemp" give - I'm guessing nothing.

veerain 02-22-2015 10:32 PM

Quote:

root@FPP:/home/pi/media/sequences# echo cp $nexttemp MasterFseq.fseq
+ echo cp MasterFseq.fseq
cp MasterFseq.fseq
Your nexttemp variable is empty.

First set by:

Code:

export nexttemp="B_254_TieDyeKaleidoscope.fseq"
Then execute the copy command.

suicidaleggroll 02-23-2015 10:29 AM

Quote:

Originally Posted by veerain (Post 5321811)
First set by:

Code:

export nexttemp="B_254_TieDyeKaleidoscope.fseq"
Then execute the copy command.

There's no reason for export, just set the variable normally, unless it needs to be used by subprocesses as well.

johnty 02-23-2015 07:16 PM

Quote:

Originally Posted by syg00 (Post 5321766)
Looks like you have a file called nexttemp, not a variable.
What does "echo $nexttemp" give - I'm guessing nothing.

Oh, exactly right. An echo command shows nothing. Somewhere in my parsing and manipulation of the target character string, the variable became a file. Making it a variable again does indeed work with the cp $var command.

Brain fade is so discouraging. Thanks for everyone's input. Great forum.


All times are GMT -5. The time now is 07:45 AM.