arun arun
arun arun

Reputation: 157

simple shell script to copy files and folders and also execute a command

I haven't written any Shell scripts before, but i have to write a simple shell script to do the following;

I will keep all the required files in a single folder and bundle it with this shell script as a tar file; so when the user runs the shell script, it needs to copy the respective files to the respective destinations.

The execution of copy as follows:

  1. copy the plugin.so file to /usrlib/mozilla/plugins/

  2. copy the .so library files to /usr/local/lib/

  3. copy some header files directories(folders) to /usr/local/include/

and finally, need to do ldconfig.

Upvotes: 8

Views: 80226

Answers (1)

Zagorax
Zagorax

Reputation: 11890

Basically, you can add in a script any command you are able to type inside the terminal itself. Then, you have two options for executing it:

  1. Execute it from the terminal with sh your_script.sh. You don't even need to give execute permission to it with this solution.
  2. Give it the execute permission and run it with ./your_script.sh.

For the second solution, you have to start the file with what is called a shebang. So your script will look like:

#!/bin/sh

cp path/to/source path/to/destination
cp path/to/source path/to/destination
cp path/to/source path/to/destination

ldconfig

echo "Done!"

Nothing else. Just write the commands one after the other. The first line is the so-called shebang and tells the shell which interpreter to use for the script.

Note: the extension for shell scripts is usually .sh, but you can actually name your file however you prefer. The extension has no meaning at all.

Good scripting!

Upvotes: 16

Related Questions