shell script for file manipulation

hi,i am using ubuntu and generally use VI editor to write shell scripts. i am required to write a shell script to copy the text of one file(a text file) into another file.While the script executes, the shell shall ask the user to input the source filename and destination filename (both these files have been initially created by using "cat" command in the terminal). after the script completes executing, the destination file should have same text as the source file.

please explain how to accomplish this task and i am new to linux scripting though i have some programming experiance in C. please don't use complicated syntax and procedures (all the forums i checked out till now did exactly that), i just need the basic and simple script to do the simple job. thanx in advance.

In your script, include the

In your script, include the following code:


read -p "Enter the name of the first file: " file1
read -p "Enter the name of the second file: " file2
cat $file1 > $file2

Of course, you can decorate this as you need, but the read command will allow you to input values into the variables. the -p "some text" generates a prompt to the user. In this example, I called the variables file1 and file2.

The cat command simply outputs the contents of file1 and the redirect input the content into file2.

with this code, file2 will be created automatically if it does not already exist. If it exists, it will overwrite the current content with the new content. If you wish to append the new content to the existing file, use a double-redirect symbol ">>" rather than the single.