LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to copy (save as) one file into multiple files (names are different) (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-save-as-one-file-into-multiple-files-names-are-different-4175547371/)

Mike_Brown 07-06-2015 06:10 PM

How to copy (save as) one file into multiple files (names are different)
 
I have a file temp.sh. I would like to save temp.sh as temp1.sh, Temp.sh, TEMP.sh, and a.sh. I am trying to use
Code:

cp temp.sh temp1.sh Temp.sh TEMP.sh a.sh
. But it does not work.

astrogeek 07-06-2015 06:31 PM

No, it doesn't. It doesn't work like that.

If you look at the error message it should be something like...

Code:

cp: target 'a.sh' is not a directory
cp will accept multiple sources but only one target. If there are multiple sources it will expect the target to be a directory.

Keith Hedger 07-06-2015 06:46 PM

You could try this:
Code:

echo -en "t1.sh\0t2.sh\0tn.sh\0"|xargs -0 -I '{}' cp /tmp/x.sh /tmp/'{}'
The args to echo are -e - use escape codes, -n - suppress newline.
Args to xargs are -0 use '0' as delimiter, -I '{}' replace '{}' with data read from stdin.
The \0 in the echo string inserts a 0, the byte NOT the character into the string.

Aia 07-06-2015 07:24 PM

Would a simple loop do?

Code:

for f in temp1 Temp TEMP a; do
    echo "cp temp.sh ${f}.sh"
done

Remove the echo and quotes if satisfied.

Keith Hedger 07-06-2015 07:26 PM

That's the beauty of linux if you dont like one solution just hang around another one will be along in a moment.


All times are GMT -5. The time now is 12:10 AM.