how to cp files to dir,using routine?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to cp files to dir,using routine?
# 1  
Old 05-21-2008
how to cp files to dir,using routine?

hi all,

I wanted to know how we can copy files to dirs, through a routine and when the file and the dir are specified as parameters for that routine and explicitly called?

Eg: suppose i want to copy file1 to /tmp then

myproc()
{
.
.
}

myproc /path/file1 /tmp/
These parameters when passed to the myproc() ,file1 should be copied to /tmp

May i know how it can be done?
# 2  
Old 05-21-2008
Code:
myproc()
{
  cp $1 $2
}

myproc /path/file1 /tmp/

# 3  
Old 05-21-2008
I have tried that, but its not working....
Says something like this, "file1 : no such file or directory"

is there any other way?

Thanks
# 4  
Old 05-21-2008
Quote:
Originally Posted by wrapster
I have tried that, but its not working....
Says something like this, "file1 : no such file or directory"
If the file don't exist that's normal.
# 5  
Old 05-21-2008
that is correct, the file doesnt exist....
However why is it that we cannot emulate the cp command ,from the routine?

How is it that when using the cp cmd it works fine,but only when parameters are passed ,and expected a cp,this thing fails???

Secondly, this function is to be included in a boot script that actually copies a few files onto /tmp....
Since this was not working unless a file was specified as the "dest" i created a dummy file in tmp(having the same name) then used a suitable () to cp from src to dest, but i get some memory issues,.....
What could be the problem?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Script to move all files in a dir into a certain dir

Hello all, I'm very new to shell scripting and need quite urgently to do this thing for my student job. I have a directory called "vectors" with a bunch of files all named ".vector". also i have for each of those files a directory with the name . I now want to move each of those *.vector files... (2 Replies)
Discussion started by: sherresh
2 Replies

3. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

4. Shell Programming and Scripting

Copy files and subdirs from dir to a new dir

Hello Comunity I am trying to make a bash shell script that it copies files and subdirs(with files) to a new dir. I would like the dest_dir to contain only subdirectories with files not other subdirs inside. it called : cpflatdir src_dir dest_dir Pleaze help me! Thank you in... (2 Replies)
Discussion started by: BTKBaaMMM
2 Replies

5. Shell Programming and Scripting

Need a script to move the files from one dir to other other dir

Need a script to move the files from one dir to other dir and at the same time it has to read the log in the source dir. Please help me ASAP. (4 Replies)
Discussion started by: viswanathkishor
4 Replies

6. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

7. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

8. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

9. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies

10. UNIX for Advanced & Expert Users

how to cp files to dir,using routine?

hi all, I wanted to know how we can copy files to dirs, through a routine and when the file and the dir are specified as parameters for that routine and explicitly called? Eg: suppose i want to copy file1 to /tmp then myproc() { . . } myproc /path/file1 /tmp/ These parameters when... (1 Reply)
Discussion started by: wrapster
1 Replies
Login or Register to Ask a Question