LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script to copy files (https://www.linuxquestions.org/questions/programming-9/bash-script-to-copy-files-526614/)

thtr2k 02-07-2007 11:50 PM

bash script to copy files
 
Hi,
i want to write a bash script to copy files, but i encounter a minor problem. My command "mycp source destination" and check for the existence of the file being copied to the new location. eg mycp ~/dir1/file1.txt ~/abc/dir2 If in dir2 has file1.txt it should automatically be file2.txt (i want to increment the number because I tried with style file1.txt.bak but don't like the look of the extension) otherwise just do the normal copy. One more thing how do i break down the $2 (ie: ~/abc/dir2/file.txt or ./def/dir2/file.txt) as directory and file. coz i want too have a prompt if the directory doesn't exist either create or terminate.
Thanks.

kshkid 02-08-2007 12:03 AM

looking for this

Code:

basename ~/abc/dir2/file.txt
Code:

dirname ~/abc/dir2/file.txt


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