Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 781
arun arun Avatar asked Sep 11 '12 19:09

arun arun


1 Answers

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!

like image 87
Zagorax Avatar answered Oct 22 '22 05:10

Zagorax