8

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.

0

1 Answer 1

16

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!

6
  • I need to package this script along with the mentioned libraries, plugin file and header files. So, who ever wish to install my plugin they just need to run this script and it will install the plugin in their Linux machine
    – arun arun
    Sep 12, 2012 at 14:50
  • @arunarun, Can't you simply create a tar.gz file with everything inside and call this script Install.sh? You could also upload the tar.gz file somewhere and then have the script to download it, decompress and do whatever else you need, in this case you can deliver to the people the script and nothing else.
    – Zagorax
    Sep 12, 2012 at 15:25
  • This is for a master thesis. so,i just plan to compress all the files and folders along with this script and create a single tar.gz file. so the users need to download the tar.gz and decompress it and after that they just need to execute the script file to install the plugin. i have a doubt, i this case how the source path should be written for example i just wnat to copy my npplugin.so file from the decompressed folder to the /usrlib/mozilla/plugins/ location.
    – arun arun
    Sep 12, 2012 at 17:20
  • Use absolute path, as you don't know where the user will extract the files.
    – Zagorax
    Sep 12, 2012 at 17:40
  • I need to do some other things in this script also. first i need to check ubuntu version, if its greater than or equal to 12 then i need to copy some more files. how to do condition checking in shell script?
    – arun arun
    Sep 22, 2012 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.