LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   positional parameters script making (https://www.linuxquestions.org/questions/linux-newbie-8/positional-parameters-script-making-940585/)

tomislav91 04-19-2012 01:21 AM

positional parameters script making
 
I was going to make some script file that must coping one folder(for example: /home/movies/terminator2) to another(that another folder must be parameter )
please help.

druuna 04-19-2012 01:24 AM

Hi and welcome to LQ,

Is there a question somewhere? We are more then willing to help, but we don't do all the work for you.

What have you tried? What did or did not work?

RootAround 04-19-2012 09:13 PM

I'm not sure whether you want to copy the directory and its contents, or just its contents. But here's a script to get you started. It addresses both cases.

The directory "thisdir" has a file in it, but "thatdir" is an empty directory
This script, copy.sh, takes one parameter, $1. The 1st copy will copy just the contents of thisdir, not the directory structure itself. The 2nd copy copies the entire thisdir directory--with its contents-- to thatdir.

Here's the copy.sh script
---------------------------------------------------
#copy the contents of -thisdir- to -thatdir-
cp -t $1 thisdir/*.*
#copy the directory -thisdir- into -thatdir
cp -r thisdir $1
echo "the contents of -thisdir- and the directory now in -$1-"
---------------------------------------------------------

After creating it, invoke copy.sh by keying in;
------------------------------------------------------
./copy.sh thatdir
-------------------------------------------------------
I'm using "thatdir" as the parameter, but you can create/use your own directories.

Note that you have to enable the execution of copy.sh with
chmod +x copy.sh

Here are some links you might find useful:

Linux Commands
Shell Script Beginners Handbook
Bash Scripting Tutorial

Hope this helps. It's always tough for a newbie.


All times are GMT -5. The time now is 08:42 AM.