A simple shell script to copy files and folders, as well as execute a command

I have not written any shell scripts yet, but I need to write a simple shell script to do the following:

I will save all the necessary files in one folder and bind it to this shell script as a tar file; therefore, when the user runs the shell script, she needs to copy the corresponding files to the appropriate destinations.

Copy execution is performed as follows:

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

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

  • copy some header files of files (folders) to / usr / local / include /

and finally you need to run ldconfig.

+7
source share
1 answer

In principle, you can add to the script any command that you can enter inside the terminal itself. Then you have two options for doing it:

  • Run it from the terminal using sh your_script.sh . You do not even need to grant permission to implement this decision.
  • Give it permission to run and run it with ./your_script.sh .

For the second solution, you should run the file with what is called shebang . So your script will look like this:

 #!/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 commands one by one. The first line is the so-called shebang and tells the shell that the interpreter should use for the script.

Note. The extension for shell scripts is usually .sh , but you can actually name your file as you prefer. Extension does not matter.

Good scripting!

+11
source

All Articles